NOTE
A big thank you to everyone involved getting NixOS available on WSL!
Followed the Quick start instructions of the nix-community/NixOS-WSL
project, but couldn’t get it work based on them.
TL;DR
(again, this probably only needed for the 22.05-5c211b47 release)Only a minor change is necessary:
Unfortunately this was only apparent after failing first and combing through the issues (see them listed below), hence this post.
Download
nixos-wsl-x86_64-linux.tar.gz
from the 22.05-5c211b47 release’s assets
(instead ofnixos-wsl-installer.tar.gz
)Run
wsl --import NixOS .\NixOS\ nixos-wsl-x86_64-linux.tar.gz --version 2
For reference:
wsl --import <Distro> <InstallLocation> <FileName> [Options]
Run NixOS
wsl -d NixOS
There are 4 closed issues regarding this:
- #67: 21.11-d89f18a1 fails after initial import with
nsenter: failed to parse pid: '-p'
- #69: nsenter: failed to parse pid: ‘-p’
- #73: wsl: nsenter: failed to parse pid: ‘-p’
- #87: nsenter: failed to parse pid: ‘-p’
My issue was exactly what can be seen in #87 so this is what I had to do to fix it:
-
List available distros (in case you didn’t use the Quick start’s default of
NixOS
)wsl -l -v
-
Shut down NixOS (or whatever processes were running trying to start it)
wsl -t NixOS
-
Delete the NixOS distro
wsl --unregister NixOS
-
Go to the TL;DR section above, and follow the steps from there.
Relevant wsl
subcommands / options for reference:
--list, -l [Options]
Lists distributions.
Options:
--all
List all distributions, including distributions that are
currently being installed or uninstalled.
--running
List only distributions that are currently running.
--quiet, -q
Only show distribution names.
--verbose, -v
Show detailed information about all distributions.
--online, -o
Displays a list of available distributions for install with 'wsl.exe --install'.
--set-default, -s <Distro>
Sets the distribution as the default.
--terminate, -t <Distro>
Terminates the specified distribution.
--unregister <Distro>
Unregisters the distribution and deletes the root filesystem.