WSL: Ubuntu Nix Setup
Introduction
WARNING
Make sure you have followed WSL Quick Setup Post first.
Nix and Nix flakes makes easier to install tools on Ubuntu. Although, not all of them work perfectly fine (I prefer to keep podman f.e. installed from apt) it makes easier to maintain the environment clean and reproducible.
- nix provides a package-manager with a unique declarative approach. Do not confuse with NixOs which is a Linux Distribution on its own.
- nix flakes provides a standard way to use nix for installing packages easily with nix files.
Install
Install nix multi-user with daemon
curl -L https://nixos.org/nix/install | sh -s -- --daemon
Log out, wait at least 8 seconds and log in again
exit
wsl -t Ubuntu
# wait at least 8 seconds
wsl -d Ubuntu
Enable Flakes
Enable flakes by creating ~/.config/nix/nix.conf
mkdir -p ~/.config/nix/
touch ~/.config/nix/nix.conf
Add to ~/.config/nix/nix.conf the following (run code ~/.config/nix/nix.conf)
experimental-features = nix-command flakes
Check nix flakes works
nix flake --help
nix run nixpkgs#hello
# Hello, World!