Frequently Asked Questions



How do I fix: error: querying path in database: database disk image is malformed


sqlite3 /nix/var/nix/db/db.sqlite “pragma integrity_check”

Which will print the errors in the database. If the errors are due to missing references, the following may work:

mv /nix/var/nix/db/db.sqlite /nix/var/nix/db/db.sqlite-bkp sqlite3 /nix/var/nix/db/db.sqlite-bkp “.dump” | sqlite3 /nix/var/nix/db/db.sqlite

How to operate between Nix paths and strings?

How do I fix: error: current Nix store schema is version 10, but I only support 7

This means you have upgraded Nix sqlite schema to a newer version, but then tried to use older Nix.

The solution is to dump the db and use old Nix version to initialize it:

/path/to/nix/unstable/bin/nix-store --dump-db > /tmp/db.dump
mv /nix/var/nix/db /nix/var/nix/db.toonew
mkdir /nix/var/nix/db
nix-store --init (this is the old nix-store)
nix-store --load-db < /tmp/db.dump

How nix decides which parts of the environment affect a derivation and its sha256 hash

How to pin nixpkgs to a specific commit/branch?

Ways to provide/pin nixpkgs:

  • nix-channel --add URL nixpkgs && nix-channel --update sets it globally for the user, but it doesn’t allow precision (pinning to specific version)
  • As environment variable: $NIX_PATH=URL
  • -I command line parameter to most of commands like nix-build, nix-shell, etc
  • Using builtins.fetchTarball function that fetches the channel at evaluation time

Possible URL values:

  • Local file path. Using just . means that nixpkgs is located in current folder.
  • Pinned to a specific commit:
  • Using latest channel, meaning all tests have passed:
  • Using latest channel, but hosted by github:
  • Using latest commit for release branch, but not tested yet:


  • nix-build -I ~/dev
  • nix-build -I ~/dev
  • nix-build -I nixpkgs=
  • NIX_PATH=nixpkgs= nix-build ...
  • Using just Nix:
with import (fetchTarball {};

stdenv.mkDerivation { … }

How to build reverse dependencies of a package?

nox-review wip

I’m getting: writing to file: Connection reset by peer

Too big files in src, out of resources (HDD space, memory)

What are channels and different branches on github?

Subquestion: how stable is unstable?

How do I mirror tarballs?

We have a content-addressed tarball mirror at for this purpose. “fetchurl” will automatically use this mirror to obtain files by hash. However:

How can I manage dotfiles in $HOME with Nix?

See following solutions:

Are there some known impurities in builds?


  • CPU (we try hard to avoid compiling native instructions, but rather hardcode supported ones)
  • current time/date
  • FileSystem (ext4 has a known bug creating empty files on power loss)
  • Kernel
  • Timing behaviour of the build system (parallel Make not getting correct inputs in some cases)


How do I connect to any of the machines in NixOS tests?

Apply following patch:

diff --git a/nixos/lib/test-driver/ b/nixos/lib/test-driver/
index 8ad0d67..838fbdd 100644
--- a/nixos/lib/test-driver/
+++ b/nixos/lib/test-driver/
@@ -34,7 +34,7 @@ foreach my $vlan (split / /, $ENV{VLANS} || "") {
     if ($pid == 0) {
         dup2(fileno($pty->slave), 0);
         dup2(fileno($stdoutW), 1);
-        exec "vde_switch -s $socket" or _exit(1);
+        exec "vde_switch -tap tap0 -s $socket" or _exit(1);
     close $stdoutW;
     print $pty "version\n";

And then the vde_switch network should be accessible locally.

How to bootstrap NixOS inside an existing Linux installation?

There are a couple of tools:


What to do if cache/hydra is down or unreachable?

Pass following to Nix commands:

  • --option connect-timeout 5 to wait only 5 second on binary package
  • --fallback to build from source if binary package fetching fails

How do I add a new binary cache?

Using NixOS:

trustedBinaryCaches = [ "" "" ];
binaryCaches = trustedBinaryCaches;
binaryCachePublicKeys = [ "" ];

Using Nix:

$ echo "trusted-binary-caches =" >> /etc/nix/nix.conf
$ nix-build helpers/bench.nix --option extra-binary-caches`

How do I force nix to re-check whether something exists at a binary cache?

Nix caches the contents of binary caches so that it doesn’t have to query them on every command. This includes negative answers (cache doesn’t have something). The default timeout for that is 1 hour as of writing.

To wipe all cache-lookup-caches:

$ rm $HOME/.cache/nix/binary-cache-v5.sqlite*

Alternatively, use the narinfo-cache-negative-ttl option to reduce the cache timeout.