What WSL modules provide
The WSL module adapts your NixOS configuration to work seamlessly in WSL2, handling Windows interop, disabling incompatible services, and configuring the environment for the best WSL experience.Windows interop
Open Windows programs and files from WSL
Smart defaults
Disables services that don’t work in WSL
Start menu integration
Launch WSL from Windows Start menu
Network sharing
Uses Windows networking stack
Module configuration
The WSL module is implemented in a single file that configures all WSL-specific settings.Core WSL settings
WSL integration
WSL integration
modules/wsl/default.nix
enable = true- Activates WSL2 integrationdefaultUser- Uses your main user from garden configstartMenuLaunchers = true- Adds WSL to Windows Start menuinterop.register = true- Enables running Windows executablesinterop.includePath = false- Doesn’t pollute PATH with Windows binaries
Disabled services
Services that don't work in WSL
Services that don't work in WSL
modules/wsl/default.nix
- WSL2 uses the Windows network stack
- No direct hardware access for disk monitoring
- Windows handles DNS resolution and firewall rules
- Security features like AppArmor don’t work in containers
Windows integration
Opening files in Windows
Opening files in Windows
modules/wsl/default.nix
Other settings
Theme and appearance
Theme and appearance
modules/wsl/default.nix
Usage example
The valkyrie system uses the WSL module:systems/default.nix
class = "wsl" setting automatically imports the WSL module through the class module system, which loads modules/wsl/default.nix.
Setting up WSL
Prerequisites
You need Windows 10 version 2004+ or Windows 11 with WSL2 installed:Installing NixOS on WSL
-
Build the WSL system configuration:
- Import into WSL using nixos-wsl’s import script (see NixOS-WSL documentation)
-
Launch your NixOS WSL instance:
Rebuilding your system
After making configuration changes:Key features
Automatic service disabling
The module automatically disables services that:- Require direct hardware access
- Conflict with Windows services
- Don’t make sense in a container environment
Windows interoperability
Withwsl-open, you can seamlessly open files and URLs in Windows applications while working in the Linux environment.
Consistent with NixOS
The WSL module imports your regular NixOS modules, so you get the same configuration as your other systems with only WSL-specific overrides.Network transparency
WSL2 shares networking with Windows, so:- Services in WSL are accessible from Windows via
localhost - Windows firewall controls all network access
- DNS resolution works through Windows
Differences from standard NixOS
WSL has limitations compared to bare-metal NixOS:No systemd-boot or GRUB
No systemd-boot or GRUB
WSL doesn’t boot like a regular system. The Windows kernel loads WSL2 instances, so bootloader configuration is irrelevant.
No direct hardware access
No direct hardware access
WSL2 runs in a lightweight VM, so direct hardware access (GPU pass-through aside) isn’t available. Services like smartd that monitor disks won’t work.
No firewall control
No firewall control
The Windows firewall controls network access. WSL networking is bridged through Windows.
No systemd-resolved
No systemd-resolved
DNS resolution is handled by Windows, not systemd-resolved.
Advanced configuration
GPU acceleration
WSL2 supports GPU acceleration for machine learning and graphics:Custom default user
The WSL module usesconfig.garden.system.mainUser, which you set in your system configuration:
systems/valkyrie/users.nix
File system access
Access Windows files at/mnt/c/ and other drives:
Next steps
NixOS modules
Full NixOS system configuration
Home Manager modules
Per-user configuration that works in WSL