4 reasons I use NixOS in WSL instead of Ubuntu or Fedora

When it comes to WSL, most go for Ubuntu or Fedora and there’s a good reason for it. The learning curve is close to zero, whether you’re familiar with Linux or not. Plus there’s enough documentation and community support available to get you out of any mess. But I personally like to experiment with different Linux distros so I also tried NixOS in WSL. If you care more about a reproducible, declarative workspace than about sticking with a familiar apt or dnf workflow, I’d suggest you try it too.

NixOS turns WSL into an environment you can rebuild, clone, and roll back with a single command, yet it still gives you the same GUI, GPU, and USB features that Ubuntu and Fedora get under modern WSL.

Related

How I used NixOS to make my home lab truly immutable

Safety and security are NixOS’s calling cards

4

Declarative approach

Plus cross-platform parity

Everything about a NixOS installation is declared inside a single text file, usually configuration.nix (or a flake.nix that imports it). When you run nixos-rebuild switch, the operating system is built directly from that file’s contents. No part of the system is hidden in interactive history or half-remembered package commands.

There are a lot of advantages to this approach. One is reproducibility. You can reinstall it on another PC or in CI and you get a byte-identical setup. Git history shows when a package was added, who added it, and why. And if you lose the VM image, you can keep the repo, recreate the system with one command and minutes of download time. The same flake can target WSL, a bare-metal server, a cloud VM or macOS via nix-darwin.

Perhaps the most persuasive reason for me is how NixOS in WSL helps unify development environments across all platforms. You can run NixOS on a headless Linux server for deployments, and also use Nix through Home Manager and nix-darwin on a Mac. By using NixOS in WSL on your Windows machine, your Windows dev setup, Linux servers, and macOS laptop can all stay in sync with the exact same versions of software.

3

Atomic updates

Go back if something is messed up

Screenshot showing nixos console

The upgrade process in NixOS makes life much easier. When you tweak your config and run nixos-rebuild switch, Nix builds the new system state in the background. It only switches over once everything is ready, so there are no partial updates that leave your setup in a broken state. If an upgrade introduces a bug, like a driver failure, you can simply reboot into a previous generation to fix it.

Even in WSL, NixOS keeps a full history of your system states. Each rebuild is versioned, letting you roll back easily without debugging or reinstalling anything. This is something you don’t get natively with apt or dnf inside typical WSL distros.

2

Per-project dev shells with nix develop

No containers needed

Another killer feature is how NixOS and the Nix toolchain handle development environments. If you often work on multiple projects with conflicting dependencies, such as different Node versions or Python libraries, you don’t need to juggle Docker containers or clutter your base system. Instead, you can use Nix’s per-project development shells.

The Nix shell tooling lets you spawn an environment with exactly the tools required for that project. Nothing persists once you exit. This is a major shift from how things usually work on Ubuntu or Fedora, where I would typically install and uninstall packages, or rely on tools like virtualenv and nvm to simulate isolation.

1

WSL integration is smooth

You have everything you need

Using the nixpkgs repository on NixOS

There’s no point in using Linux on WSL if it doesn’t integrate well with Windows. NixOS in WSL works well with all the key features of WSL2. The latest NixOS-WSL release even includes native support for WSL’s built-in systemd, which means I can run background Linux services in WSL without any hacks.

Previously, the lack of PID 1 and systemd in WSL was a major limitation. But now, my NixOS WSL instance boots with systemd just like a regular Linux system. This enables features like timers, socket-activated services, and more, all of which are now supported by Ubuntu and Fedora on WSL as well.

Hardware and UI integration is equally seamless. If you need GPU acceleration for Linux apps, NixOS WSL includes an option to use the Windows host’s OpenGL graphics driver, allowing Linux GUI apps to take advantage of the GPU.

Also, if you want to access your NixOS files via a Windows application, simply point to the file path of:

\wsl.localhostNixOS

For example, I might want to use VS Code on the Windows side of my system. To point to the code living on my NixOS side, I’d point VS Code to:

\wsl.localhostNixOShomeanuragGitmy-repo-name

NixOS is fun to use

NixOS is an exciting Linux distro that finally convinced me to give up on Windows. I dual-booted it alongside Windows for the longest time, but I recently started using it as my primary OS. It’s packed with features that are genuinely useful, and it’s one of the few operating systems that can help make your home lab truly immutable. While you’re exploring options, check out these four Linux distros you should consider using instead of upgrading to Windows 11.

Related

5 reasons I can’t go back to Windows after trying Linux

As weird as it may sound, Linux has more game-changing QoL features than Windows

Continue Reading