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 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 Alpine linux into the Windows Subsystem for Linux 2 (hereafter, WSL)
- Minimally configuring Alpine as necessary for installing Nix and conveniently using it.
- Installing Nix within the Alpine WSL distribution.
- Configure 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 Alpine 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
-
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.
- The folder in which you'd like to place your WSL distro.
- 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 Alpine
. If you have another installed and you didn't accept the default distro name, you needwsl -d WhateverYouNamedYourDistro
. To get root access usewsl --user root
. -
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 2 is a goofy environment. At the core it is a virtualized Linux kernel, but it uses a custom init system, which makes it an awkward fit with distributions that rely heavily on systemd1. This includes NixOS, Ubuntu, Debian, and Fedora, among many others. So if WSL is handling the kernel and init system, what else is left of these full featured distributions? Not much I care about, honestly. I'm not going to be running persistent services there. WSL isn't really designed to be used by different Windows users, so the user management stuff isn't useful. My selection of package versions and service orchestration is going to come from the Nix config associated with my development projects, not from the OS curation. So 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.
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, but there hasn't been a NixOS-WSL release since then (as of July 16, 2023).
Basically because it's the most minimal commonly used WSL distro. I probably would have preferred a minimal glibc based distro, but there isn't one that's particularly popular in combination with WSL.
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.
Footnotes
-
Official systemd support was added to WSL Sep 21, 2022, starting with version 0.67.6, so systemd-reliant distributions should be getting better. ↩