NixOS on WSL
How to setup NixOS on Windows Subsystem for Linux (WSL)
NixOS on WSL
Windows Subsystem for Linux (WSL)
How to setup NixOS on Windows Subsytem for Linux.
Enable WSL
Run the following command from an admin shell:
Using PowerShell
1
2
3
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -All
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -All
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
Or using Command Prompt and DISM
Run the following command from an admin shell:
1
2
3
DISM /Online /Enable-Feature /All /FeatureName:Microsoft-Windows-Subsystem-Linux /norestart
DISM /Online /Enable-Feature /All /FeatureName:VirtualMachinePlatform /norestart
DISM /Online /Enable-Feature /All /FeatureName:Microsoft-Hyper-V /norestart
Install WSL
Run the following command from a non-admin shell:
1
wsl --install
Updating WSL
Run the following command from a non-admin shell:
1
wsl --update --web-download
Running WSL
To enter the WSL environment simply execute:
1
wsl
This will launch the default linux OS.
1
2
wsl --install
wsl --update --web-download
If you run wsl
and nothing happens (no errors reported, but WSL does not launch). Then run the above commands again.
Installing NixOS-WSL
- First, download the latest release.
- Import NixOS-WSL (run these commands in the same folder where the release
nixos-wsl.tar.gz
was downloaded):- Using PowerShell:
1
wsl --import NixOS $env:USERPROFILE\NixOS\ nixos-wsl.tar.gz
- Using Command Prompt:
1
wsl --import NixOS %USERPROFILE%\NixOS\ nixos-wsl.tar.gz
- Using PowerShell:
- Enter the NixOS environment
1
wsl -d NixOS
- After the initial installation, you need to update your channels once, to be able to use
nixos-rebuild
:1
sudo nix-channel --update
To optionally set NixOS as the default for WSL:
1
wsl -s NixOS
Enable flakes
In order to use Nix flakes you need to add the following line to your System Configuration:
nix.settings.experimental-features = [ "nix-command" "flakes" ];
This post is licensed under CC BY 4.0 by the author.