NixOS on Microsoft Windows 11 using WSL2
NixOS is my go-to Linux distribution, providing a Functional approach to packaging & configuration management.
There are a couple of steps to enable NixOS on top of the Windows Subsystem for Linux 2. Running native NixOS is a better approach then to use Nix on Windows (using Ubuntu).
NOTE
An earlier version was published as Nix on Windows 10 in 2019.
Enable WSL if you haven’t done so.
1
wsl --install --no-distribution
The --no-distribution
just activates wsl2, see wsl docs.
Reboot your pc.
Import & Install NixOS on WSL2
We are going to use the nix-community/NixOS-WSL base.
-
Download the latest release
-
Import the image to WSL
1
wsl --import NixOS %userprofile%\AppData\Local\WSL\NixOS .\Downloads\NixOS\nixos-wsl.tar.gz
%userprofile%\AppData\Local\WSL\NixOS
is an arbitrary location, adjust to your needs. -
Run NixOS
1
wsl -d NixOS
-
Optionally make NixOS the default
1
wsl -s NixOS
Our first run
-
Run a
nix-channel
update asroot
1
sudo nix-channel --update
-
You can start using NixOS
e.g.
nix-shell -p htop
Definitely check