An opinionated nix wsl buid
README.md

NixOS WSL #

Overview #

This repository provides a pre-configured NixOS development environment for WSL2, tailored for AIMMS platform development. It includes:

  • NixOS 26.05 with flakes enabled
  • Home Manager for user-level configuration management
  • Development tools: Neovim (default editor), Git, and direnv with automatic shell activation
  • Container support: Podman for containerized workflows
  • Security tools: sops and age for secrets management
  • nix-ld: For running non-NixOS binaries
  • Automated development shells: Using direnv and flake-based environments

This configuration provides a reproducible, declarative development environment that can be version-controlled and shared across teams.

Table of Contents #


Prerequisites #

Before using this configuration, you need WSL2 and NixOS-WSL installed on your Windows machine.

Installing WSL on Windows #

Requirements:

  • Windows 10 version 2004 or higher (Build 19041 or higher) or Windows 11
  • Administrator access to your Windows machine

Installation Steps:

  1. Open PowerShell or Command Prompt as Administrator

    • Right-click the Start button
    • Select "Windows PowerShell (Admin)" or "Terminal (Admin)"
  2. Install WSL with the default Ubuntu distribution

    wsl --install
    
  3. Restart your computer when prompted

Method 2: Manual Installation #

If you need more control or the simple method doesn't work:

  1. Enable WSL feature

    dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
    
  2. Enable Virtual Machine Platform

    dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
    
  3. Restart your computer

  4. Download and install the WSL2 Linux kernel update package

  5. Set WSL2 as the default version

    wsl --set-default-version 2
    

Verification #

To verify WSL is installed correctly:

wsl --list --verbose

This should show your installed Linux distributions and their WSL version.


Installing NixOS-WSL #

NixOS-WSL is a port of NixOS for WSL that provides a fully functional NixOS distribution under WSL.

Requirements:

  • WSL2 must be installed and enabled (see above)
  • Windows 10 version 2004+ or Windows 11

Installation Steps:

  1. Download the latest release

  2. Import the tarball into WSL

    Open PowerShell and run:

    wsl --import NixOS .\NixOS\ nixos-wsl.tar.gz --version 2
    

    Replace .\NixOS\ with your desired installation path.

  3. Launch NixOS

    wsl -d NixOS
    

Option 2: Building from Source #

If you want to customize your installation or use the latest development version:

  1. Clone the repository (in an existing Linux WSL distribution or on Linux):

    git clone https://github.com/nix-community/NixOS-WSL.git
    cd NixOS-WSL
    
  2. Build the tarball

    nix-build -A system
    
  3. Import into WSL (from PowerShell):

    wsl --import NixOS .\NixOS\ result\tarball\nixos-wsl.tar.gz --version 2
    

Setting as Default Distribution (Optional) #

To make NixOS your default WSL distribution:

wsl --set-default NixOS

Using This Configuration #

Once you have NixOS-WSL installed, you can apply this repository's configuration to set up your development environment.

Quick Start #

  1. Clone this repository

    Inside your NixOS-WSL terminal:

    git clone https://gitlab.aimms.com/aimms/platform/nix-wsl.git
    cd nix-wsl
    
  2. Apply the configuration

    From the cloned repository directory:

    nixos-rebuild switch --option extra-experimental-features pipe-operators --flake .# --sudo
    

    This will:

    • Build the NixOS configuration with all specified packages
    • Set up home-manager for user configuration
    • Enable flakes and experimental Nix features
    • Configure direnv for automatic development shell activation
  3. Start using your environment

    Open a new terminal or source your bashrc:

    source ~/.bashrc
    
  4. Register the MCP server with Claude Code (one-time)

    Register the NixOS MCP server with Claude Code:

    claude mcp add --scope user nixos mcp-nixos
    

    Register the codebase-memory-mcp server globally with Claude Code:

    claude mcp add --scope user codebase-memory-mcp codebase-memory-mcp
    

    Register the Playwright MCP server globally with Claude Code:

    claude mcp add --scope user playwright playwright-mcp-fixed
    

    (playwright-mcp-fixed, not bare playwright-mcp — the bare binary crashes on every browser call; see CLAUDE.md → "Playwright MCP Server" for why.) Verify inside Claude Code with /mcp — the nixos, codebase-memory-mcp, and playwright server should appear connected.


What Gets Installed #

After applying this configuration, your system will have:

  • Editor: Neovim (with vi/vim aliases, Node.js, Python, Ruby support)
  • Containers: Podman with default network and DNS
  • Shell tools: Bash with direnv integration
  • Development: Git, wget, sops, age
  • Nix features: Flakes, recursive-nix, nix-ld for binary compatibility
  • AI tooling: mcp-nixos — MCP server for real-time NixOS package/option queries in Claude Code; codebase-memory-mcp — MCP server for codebase knowledge-graph queries in Claude Code; playwright-mcp — MCP server for browser automation in Claude Code

Configuration Files #

You can customize this configuration by editing:

  • configuration.nix: System-level settings

    • Podman configuration
    • Neovim and other system programs
    • nix-ld for binary compatibility
    • Experimental Nix features
  • home.nix: User-level settings (via Home Manager)

    • User packages (wget, sops, age)
    • Git and Bash configuration
    • direnv integration
  • flake.nix: Flake configuration

    • NixOS and package versions (nixos-26.05)
    • Home Manager integration
    • Development shell with project tools (cocogitto)

After making changes, reapply the configuration:

nixos-rebuild switch --flake .# --sudo

Automated Development Shell Activation #

This repository includes automated development shell activation using direnv. When you enter the nix-wsl directory, the development environment defined in flake.nix is automatically loaded.

How It Works #

  1. direnv integration: Configured in home.nix, direnv is automatically installed and hooked into bash.

  2. .envrc file: Contains use flake to load the development shell.

  3. Development shell: Defined in flake.nix, includes tools like cocogitto for conventional commits in this project. Other projects may define different tools in their development shell definitions in flake.nix.

Verification #

After applying the configuration with

nixos-rebuild switch --flake .# --sudo

Open a new terminal or source your bashrc

source ~/.bashrc

When you enter the nix-wsl directory, direnv will automatically load the development environment. You can verify it's working:

Check direnv status

direnv status

Verify development tools are available

type -a cog

The cog command from cocogitto should be available without manual activation.

First Time Setup #

If this is your first time using direnv in this directory, you may need to allow it:

direnv allow

After this, the environment will load automatically whenever you enter the directory.


Reference #

Troubleshooting #

  • If NixOS won't start: Try wsl --shutdown and restart
  • Reset installation: Remove with wsl --unregister NixOS and reimport
  • Check logs: Use journalctl -xe inside NixOS-WSL

Useful WSL Commands #

  • List installed distributions: wsl --list --verbose
  • Set default distribution: wsl --set-default <DistributionName>
  • Shutdown WSL: wsl --shutdown
  • Update WSL: wsl --update
  • Check WSL version: wsl --version

Additional Resources #