Introduction
As a developer who traditionally dual-boots Windows and Linux, I’ve been exploring ways to create reproducible system configurations. Building on my previous work with NixOS and Windows 11 reproducible installations, I decided to evaluate Windows Subsystem for Linux (WSL) as a development environment. While this setup won’t replace my primary development machine, it offers an intriguing approach to lightweight development tasks.
Prerequisites
Before we begin, ensure you have:
- Windows 11 with administrator access
- At least 2GB of free disk space
- Basic familiarity with command line interfaces
Installing WSL2 with NixOS
Follow these steps to set up NixOS on WSL2. All commands should be run in Command Prompt, opened as admin, unless specified otherwise.
-
Download the latest
nixos-wsl.tar.gz
from the NixOS-WSL releases page -
Install WSL2 without a default distribution:
$ wsl --install --no-distribution
-
Enable virtualization support:
$ dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
-
Restart your system to apply changes
-
Open PowerShell (x86) as administrator and navigate to your downloads directory:
$ wsl --import NixOS $env:USERPROFILE\NixOS\ nixos-wsl.tar.gz --version 2
-
Close your terminal, and open it again. Ensuring you start a NixOS session. Then we’ll update our NixOS channels by running:
$ sudo nix-channel --update
-
Set NixOS as your default WSL distribution:
$ wsl -s NixOS
After completion, launch Windows Terminal to access your NixOS environment:
Configuring NixOS
To maintain a reproducible configuration, I store my NixOS settings in a toolbox repository. Here’s how I leverage it:
-
Create a temporary development environment:
$ nix-shell -p git -p vim -p just -p tmux -p nixos-rebuild
-
Configure SSH access:
- Set up new SSH keys or import existing ones
- Create your
~/.ssh/config
file - You can see my SSH keys guide for detailed instructions
-
Clone your configuration repository:
$ git clone git@github.com:GregHilston/toolbox.git
$ cd toolbox/nixos
-
Link your configuration:
$ sudo ln -sf "$HOME/Git/toolbox/nixos/hosts/pcs/foundation/default.nix" /etc/nixos/configuration.nix
Graphical Applications: An Unexpected Benefit
One of the most surprising advantages of this setup is seamless integration with Windows for graphical applications. WSL2’s support for X11 and Wayland enables running NixOS GUI applications directly on Windows.
For example, with Obsidian installed on both systems:
This integration integration has the:
- Windows Obsidian: Access Windows filesystem vaults
- NixOS Obsidian: Work with NixOS filesystem vaults
For technical details on this feature, refer to the Microsoft WSL GUI documentation.
Current Status and Future Plans
This setup was inspired by Mitchell Hashimoto’s workflow, which he demonstrates in his detailed video guide. While he uses macOS with VM Fusion, I’m exploring the Windows/WSL2 approach, as I do not own a Mac.
I plan to use this configuration for several months to evaluate its effectiveness. As someone who traditionally avoids Windows for development, I’m both skeptical and curious about the potential of this setup. Future blog posts may document my findings and any significant improvements to the workflow.