NixOS WSL 2 error with 22.05-5c211b47: nsenter: failed to parse pid: '-p'

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.

  1. Download nixos-wsl-x86_64-linux.tar.gz from the 22.05-5c211b47 release’s assets
    (instead of nixos-wsl-installer.tar.gz)

  2. Run

    wsl --import NixOS .\NixOS\ nixos-wsl-x86_64-linux.tar.gz --version 2
    

    For reference:

     wsl --import <Distro> <InstallLocation> <FileName> [Options]
    
  3. Run NixOS

     wsl -d NixOS
    

There are 4 closed issues regarding this:

  1. #67: 21.11-d89f18a1 fails after initial import with nsenter: failed to parse pid: '-p'
  2. #69: nsenter: failed to parse pid: ‘-p’
  3. #73: wsl: nsenter: failed to parse pid: ‘-p’
  4. #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:

  1. List available distros (in case you didn’t use the Quick start’s default of NixOS)

    wsl -l -v
    
  2. Shut down NixOS (or whatever processes were running trying to start it)

    wsl -t NixOS
    
  3. Delete the NixOS distro

    wsl --unregister NixOS
    
  4. 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.
Hosted by Flying Circus.