Creating a proper NixOS distrbution for WSL2

With Windows 10 2004 being released with WSL2 supports in general availablity, I’ve started to work on packaging some of the prototypes to create a NixOS distribution that could work on the WSL2 with the “standard flow” that is expected when installing a WSL distribution.

I have a base working project, forked from Trundle’s repository with some modifications to make it compatible with a custom DistroLauncher implementation you can find here.

Recently, with WSL2, Nix started to work within other distributions (I’ve used it over a Debian distribution in WSL2 for the last days and it worked well). The logical next step would be to provide NixOS itself as a WSL2 distribution.

I’m trying to find people that would be interested in making this a working project, and maybe (on the long-term run) upstream some part it.

What would need be done

The big blocker is systemd. It’s known to cause trouble within WSL2 distributions. There are some workaround like genie that have been able to do the job by using nsenter. It’s really close to Trundle’s syschdemd.sh script.

What’s working

  • Building a NixOS tarball that can be imported and configured.
  • Having a launcher that’s able to configure and register the distribution.

What’s needing to be fixed:

  • The current solution replaces the root shell with a wrapper script that defaults to the namespace. The issue with this method is that it always falls back to the default user, making root shell not usable.
  • When executing a nixos-rebuild switch, it fails with strange dbus/systemd errors inside the namespace.
  • Probably a lot of other things…

What would be nice to have:

  • Building the install.tar.gz when a channel is updated, then rebuilding the application, maybe packaging automatically ?
  • Putting the WSL configuration defaults to <nixpkgs/nixos/modules/virtualisation/wsl-image.nix> for instance.
18 Likes

Any news? Since I’m forced to use windows on work I’m looking forward for this to happen. Trying to get myself more familiar with wsl2 things now…

Hello,
I haven’t had the time to work on it recently, and I will not have this time before august.
If you want to use Nix at work for now, you could install a Debian WSL distribution and then install Nix on top of it :slight_smile:.

Thanks! So the regular installation method works now? I’ll try it later