This project aims to make it easy to get a Nix development environment up and running on Windows 11. You run a powershell script, answer four or five questions (that come with sane defaults if you're not picky) and in a few minutes you'll have a WSL setup ready to clone repos and do Nix builds.
It does so by
- Installing a linux distribution into Windows Subsystem for Linux 2 (hereafter, WSL)
- Minimally configuring that distribution as necessary for installing Nix and conveniently using it.
- Installing Nix within WSL distribution.
- Configuring the Nix installation and user profile in a somewhat opinionated but fairly lightweight manner:
- Enable the
nix-command
andflakes
experimental features. - Install ssh, git, and vim into the user profile.
- Within the WSL distribution ~/.ssh folder, create symlinks to the user's Windows SSH keys.
- Enable the
-
Enable virtualization and WSL2.
-
Have git, ssh, and powershell installed in Windows 11.
-
Clone this repo:
git clone [email protected]:scottstephens/nix-wsl-bootstrap
-
cd into either Debian or Alpine folder, depending on which distribution you'd like to use.
-
Run
install.ps1
. It will ask you for- The linux username you'd like to use within WSL.
- Your full name.
- What you'd like to name your WSL distribution. (Alpine only)
- The folder in which you'd like to place your WSL distro. (Alpine only)
- Whether you'd like a multi-user or single-user install.
Sane defaults are provided for all of these, if you're not picky you will only need to press enter 5 times.
-
After the installation is finished, enter WSL in the usual manner. If it's your only WSL distribution, all you need is
wsl
. If you have another installed, you'll needwsl -d DistroName
. -
Once in the WSL environment, you're ready to git clone any repos you want to work with, and use nix commands to build them.
WSL is quite handy for development using Nix, but a bit of a pain to set up. I think for this use case, the desirable setup will be quite similar for different people, because WSL will be used almost entirely for development, and the selection of package versions and service orchestration is going to come from the Nix config associated with the development projects, obviating much need for configuring the actual WSL distribution. All I really want is nix, git, and ssh, and the config I need to use them. And that's exactly what this script gives you.
Alpine was my original choice because it was the most minimal commonly used WSL distribution. I eventually ran into problems because I could not get kvm to work on Alpine, which meant that building Amazon AWS AMIs won't work, which was one of my core use cases.
Debian was the next most minimal, so that's what I tried next.
I tried it. It kept breaking when upgraded. Bootstrapping the config to the point where you can clone a git repo and run a nix build was also more challenging. Official systemd support has been added to WSL since I last tried NixOS-WSL, and a NixOS-WSL release has since come out that uses it, but I haven't tried it again yet.
I like them, as do many others. If you don't, they're easy to ignore.
If you know somebody who doesn't have git and ssh in their login profile, I'd like to meet them.
This is a little dicier. The real reason of course is that I use vim, but I do believe it's substantially more popular than emacs or nano. An option for those wouldn't be a terrible idea.
Needed to make git clone of a private repo work out of the box, which was a primary design goal.