- This note is about how to set up Nix on any WSL Linux distro.
- This note is different from installing NixOS on WSL (which is more about how to install NixOS as a distribution on WSL).
According to this link, Nix can be installed on WSL in two ways:
- Multiuser installation
- Single-user installation
Prerequisites
I will be installing it for multiuser, but it requires WSL with Systemd enabled. Read this guide for how to configure systemd in WSL. But in short,
-
Ensure you are running WSL version
0.67.6or higher. Confirm it by runningwsl --version. -
Make sure the following lines are added in
/etc/wsl.conf(you might need to run your editor with sudo privileges, e.g.Βsudo nanoΒ /etc/wsl.conf):[boot] systemd=true -
Close all the WSL distro Windows and run
wslΒ --shutdownfrom PowerShell to restart your WSL instances. -
Run the WSL distro again, you should have
systemdrunning. You can confirm this by running:systemctl status
Installation
-
Install Nix for the multiuser, using the following command:
sh <(curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install) --daemonThe above command will do a couple of things:
- Set up
nix-daemon.serviceandnix-daemon.socketas Systemd services - Install Nix at
/nix - Take backups of shell files
- Create local users and a local group
nixbldto run Nix builds
- Set up
-
Restart the WSL shell again to load the changes.
-
Verify the Nix installation by running:
nix --version.
Uninstallation
Read this guide on how to remove a multiuser installation from WSL / Linux.
