nix-shell under Windows WSL is broken

Created on 25 Jan 2017  路  14Comments  路  Source: NixOS/nix

WSL is the Windows Subsystem for Linux. It allows us to run Elf binaries under Windows. It works pretty well for nix-build commands but nix-shell is currently failing.

nix-shell fails because it contains a call to derivationForPath which opens up the SQLite DB. It then calls a nix-store command which fails because it also tries to open the DB. SQLite throws a "disk I/O error" for the call.

  • Can we explicitly close the database?
  • Is there a different workaround?
  • What's missing from WSL to make it operate differently to Linux?

Most helpful comment

I did an strace and saw a WAL file being created. I looked into WAL and saw that SQLite mentioned it with something about concurrency. I then looked into how Nix used WAL and found the use-sqlite-wal flag. Making an /etc/nix/nix.conf file with:

use-sqlite-wal = false

Was enough to get nix-shell to work.

  • Is the downside of this just that Nix will be a bit slower?
  • If the downside is worth it, should we modify the installer to set this when in Windows WSL?
  • Should this be fixed some other way?

All 14 comments

I did an strace and saw a WAL file being created. I looked into WAL and saw that SQLite mentioned it with something about concurrency. I then looked into how Nix used WAL and found the use-sqlite-wal flag. Making an /etc/nix/nix.conf file with:

use-sqlite-wal = false

Was enough to get nix-shell to work.

  • Is the downside of this just that Nix will be a bit slower?
  • If the downside is worth it, should we modify the installer to set this when in Windows WSL?
  • Should this be fixed some other way?

Maybe this should be reported as a bug in WSL? SQLite is a pretty widely used piece of software, so I assume we're not the only ones affected by this.

Is this fixed now?

I have confirmed this is still a problem. I've used SQLite with WAL enabled in native Windows applications and it worked fine. There must be something going on in WSL specifically. But you're right that it is only for performance.

https://github.com/Microsoft/WSL/issues/2395 seems to be the issue for WSL.

Hi all,
I tried to install Nix 2.0 into WSL Ubuntu and ran into this error. It looks related to the above discussion. Is there any work around? I have already tried enabling long-paths.

nathan@DESKTOP-PC:~$ curl https://nixos.org/nix/install | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2455  100  2455    0     0    781      0  0:00:03  0:00:03 --:--:--   781
downloading Nix 2.0 binary tarball for x86_64-linux from 'https://nixos.org/releases/nix/nix-2.0/nix-2.0-x86_64-linux.tar.bz2' to '/tmp/nix-binary-tarball-unpack.FQRi8GB3yT'...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 21.0M  100 21.0M    0     0  1519k      0  0:00:14  0:00:14 --:--:-- 1665k
performing a single-user installation of Nix...
copying Nix to /nix/store...............................
initialising Nix database...
replacing old 'nix-2.0'
installing 'nix-2.0'
unpacking channels...
error: executing SQLite statement 'pragma synchronous = normal': disk I/O error (in '/nix/var/nix/db/db.sqlite')
error: program '/nix/store/6p2gambjac7xdkd2a7w1dsxdk1q5cq4d-nix-2.0/bin/nix-env' failed with exit code 1

Have you tried to disable WAL mode as suggested in https://github.com/NixOS/nix/issues/1203#issuecomment-275089112?

That did the trick. Thanks @ThomasMader and @TerrorJack!

note that this is still broken, and the "use-sqlite-wal = false" workaround no longer works, at least on Win10 with the october 2018 update.

try adding this to /etc/nix/nix.conf

use-sqlite-wal = false
sandbox = false

I wonder if there is some way that we can detect we're running on WSL and disable WAL mode automatically?

Note that, as far as I understand, WSL 2 should fix this bug. It replaces the Linux API emulation with an actual Linux kernel.

@pcatana Tried your suggestion, but that did not work for me.

This is fixed in master and 2.3.6

Was this page helpful?
0 / 5 - 0 ratings