2 minutes
NixOs on WSL2 - When Ubun-too big
Motivation
I want to start learning c++ in earnest, and play with various python packages as well for audio embeddings.
I began setting this up in my standard UBuntu WSL2 system, but I realised that this has been polluted from quite a few years of experiments and hacking away at WSL-Windows integrations to make things play nice. I want a system that I can use for ephemeral development while the UBuntu image can stay until I’ve confirmed all my projects are correctly backed up (it’s kind of huge and I’d love to kill it)

Process
NixOS installation on WSL
After upgrading to the curent 2.4 wsl version, I canuse the wsl installer for dummies to add nix to my wsl distros as per the instructions here: https://github.com/nix-community/NixOS-WSL?tab=readme-ov-file
Quick update to my wsl terminal shortcuts later, and great, we have a nix system up and running!
But now the standard Nix setup has to begin:
HomeManager setup
First, we add the home-manager channel to our nix system:
sudo nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager
sudo nix-channel --update
Then we can open up our configuration.nix file to add relevant imports:
nix-shell -p vim
sudo vi /etc/nixos/configuration.nix
Add or update the nix system to look something like the following
{ config, pkgs, lib, ... }:
let
home-manager = builtins.fetchTarball https://github.com/nix-community/home-manager/archive/release-24.11.tar.gz;
in
{
imports =
[
(import "${home-manager}/nixos")
];
users.users.eve.isNormalUser = true;
home-manager.users.eve = { pkgs, ... }: {
home.packages = [ pkgs.atool pkgs.httpie ];
programs.bash.enable = true;
# The state version is required and should stay at the version you
# originally installed.
home.stateVersion = "24.11";
};
}
Then a rebuild switch should have home-manager in the system as a nixos module:
sudo nixos-rebuild switch
However, I’m also learning nix at the same time, and would prefer to run this as a flake. Command to rebuild usin flakes:
sudo nixos-rebuild switch --flake /etc/nixos#default
Rather than deep diving into all the steps I took to configure the flake, I’ll instead point the reader towards my current nix configuration: [github link]