@@ -9,18 +9,23 @@ A minimal root filesystem for running NixOS on WSL. It can be used with
99[ DistroLauncher] ( https://github.com/microsoft/WSL-DistroLauncher ) as
1010` install.tar.gz ` or as input to ` wsl --import --version 2 ` .
1111
12+ ## System requirements
13+
14+ NixOS-WSL is tested with the Windows Store version of WSL 2, which is now available on all supported Windows releases (both 10 and 11).
15+ Support for older "inbox" versions is best-effort.
16+
1217## Quick start
1318
14- First, [ download the latest release\' s installer ] ( https://github.com/nix-community/NixOS-WSL/releases/latest ) .
19+ First, [ download the latest release] ( https://github.com/nix-community/NixOS-WSL/releases/latest ) .
1520
1621Then open up a Terminal, PowerShell or Command Prompt and run:
1722
1823``` sh
19- wsl --import NixOS .\N ixOS\ nixos-wsl-installer .tar.gz --version 2
24+ wsl --import NixOS .\N ixOS\ nixos-wsl.tar.gz --version 2
2025```
2126
2227This sets up a new WSL distribution ` NixOS ` that is installed under
23- ` .\NixOS ` . ` nixos-wsl-installer .tar.gz ` is the path to the file you
28+ ` .\NixOS ` . ` nixos-wsl.tar.gz ` is the path to the file you
2429downloaded earlier. You might need to change this path or change to the download directory first.
2530
2631You can now run NixOS:
@@ -29,11 +34,6 @@ You can now run NixOS:
2934wsl -d NixOS
3035```
3136
32- The installer will unpack the file system and subsequently start NixOS.
33- A few warnings about file systems and locales will pop up. You can
34- safely ignore them. After systemd has started, you should be greeted
35- with a bash prompt inside your fresh NixOS installation.
36-
3737If you want to make NixOS your default distribution, you can do so with
3838
3939``` sh
@@ -68,57 +68,34 @@ If you have a flakes-enabled Nix, you can use the following command to
6868build your own tarball instead of relying on a prebuilt one:
6969
7070``` cmd
71- nix build github:nix-community/NixOS-WSL#nixosConfigurations.mysystem .config.system.build.installer
71+ sudo nix run github:nix-community/NixOS-WSL#nixosConfigurations.modern .config.system.build.tarballBuilder
7272```
7373
7474Or, if you want to build with local changes, run inside your checkout:
7575
7676``` cmd
77- nix build .#nixosConfigurations.mysystem .config.system.build.installer
77+ sudo nix run .#nixosConfigurations.your-hostname .config.system.build.tarballBuilder
7878```
7979
8080Without a flakes-enabled Nix, you can build a tarball using:
8181
8282``` cmd
83- nix-build -A nixosConfigurations.mysystem.config.system.build.installer
84- ```
83+ nix-build -A nixosConfigurations.mysystem.config.system.build.tarballBuilder && sudo ./result/bin/nixos-wsl-tarball-builder
8584
86- The resulting installer tarball can then be found under
87- ` ./result/tarball/nixos-wsl-installer.tar.gz ` .
85+ ```
8886
89- You can also build a rootfs tarball without wrapping it in the installer
90- by replacing ` installer ` with ` tarball ` in the above commands. The
91- rootfs tarball can then be found under
92- ` ./result/tarball/nixos-wsl-x86_64-linux.tar.gz ` .
87+ The resulting tarball can then be found under ` nixos-wsl.tar.gz ` .
9388
9489## Design
9590
9691Getting NixOS to run under WSL requires some workarounds:
9792
98- ### systemd support
99-
100- WSL comes with its own (non-substitutable) init system while NixOS uses
101- systemd. Simply starting systemd later on does not work out of the box,
102- because systemd as system instance refuses to start if it is not PID 1.
103- This unfortunate combination is resolved in two ways:
104-
105- - the user\' s default shell is replaced by a wrapper script that acts
106- is init system and then drops to the actual shell
107- - systemd is started in its own PID namespace; therefore, it is PID 1.
108- The shell wrapper (see above) enters the systemd namespace before
109- dropping to the shell.
110-
111- ### Installer
112-
113- Usually WSL distributions ship as a tarball of their root file system.
114- These tarballs however, can not contain any hard-links due to the way
115- they are unpacked by WSL, resulting in an \" Unspecified Error\" . By
116- default some Nix-derivations will contain hard-links when they are
117- built. This results in system tarballs that can not be imported into
118- WSL. To circumvent this problem, the rootfs tarball is wrapped in that
119- of a minimal distribution (the installer), that is packaged without any
120- hard-links. When the installer system is started for the first time, it
121- overwrites itself with the contents of the rootfs tarball.
93+ - instead of directly loading systemd, we use a small shim that runs the NixOS activation scripts first
94+ - some additional binaries required by WSL's internal tooling are symlinked to FHS paths on activation
95+
96+ Running on older WSL versions also requires a workaround to spawn systemd by hijacking the root shell and
97+ spawning a container with systemd inside. This method of running things is deprecated and not recommended,
98+ however still available as ` nixos-wsl-legacy.tar.gz ` or via ` wsl.nativeSystemd = false ` .
12299
123100## License
124101
0 commit comments