Skip to content

Commit 8735bdf

Browse files
authored
Merge pull request #295 from nix-community/prep-release
New release preparation
2 parents e7d93d0 + ff1413a commit 8735bdf

31 files changed

+393
-572
lines changed

.github/workflows/main.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ jobs:
5050
needs:
5151
- prepare
5252
runs-on: ubuntu-latest
53+
strategy:
54+
matrix:
55+
config:
56+
- modern
57+
- legacy
58+
- test
5359
steps:
5460
- name: Checkout
5561
uses: actions/checkout@v4
@@ -66,15 +72,17 @@ jobs:
6672
echo ${{ needs.prepare.outputs.version }} > ./VERSION
6773
echo $(git rev-parse HEAD) >> ./VERSION
6874
69-
- name: Build installer 🛠️
75+
- name: Build tarballs 🛠️
76+
# We can't just nix run here because nix is not on root's PATH in the container
7077
run: |
71-
nix build '.#nixosConfigurations.mysystem.config.system.build.installer'
78+
nix build .#nixosConfigurations.${{ matrix.config }}.config.system.build.tarballBuilder
79+
sudo ./result/bin/nixos-wsl-tarball-builder nixos-wsl.tar.gz
7280
73-
- name: Upload installer 📤
81+
- name: Upload tarball 📤
7482
uses: actions/upload-artifact@v3
7583
with:
76-
name: installer
77-
path: result/tarball/nixos-wsl-installer.tar.gz
84+
name: tarball-${{ matrix.config }}
85+
path: nixos-wsl.tar.gz
7886

7987
checks:
8088
name: Flake Check 📋
@@ -117,10 +125,10 @@ jobs:
117125
- name: Checkout
118126
uses: actions/checkout@v4
119127

120-
- name: Download installer 📥
128+
- name: Download tarball 📥
121129
uses: actions/download-artifact@v3
122130
with:
123-
name: installer
131+
name: tarball-test
124132

125133
- name: Execute test 🧪
126134
shell: pwsh

.github/workflows/release.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ jobs:
1414
name: Create Release 📢
1515
runs-on: ubuntu-latest
1616
steps:
17-
- name: Download installer 📥
17+
- name: Download tarball 📥
1818
uses: actions/download-artifact@v3
19-
with:
20-
name: installer
2119

2220
- name: Generate checksums 🔑
2321
run: |
22+
mv tarball-modern/nixos-wsl.tar.gz nixos-wsl.tar.gz
23+
mv tarball-legacy/nixos-wsl.tar.gz nixos-wsl-legacy.tar.gz
2424
for x in *.tar.gz; do
2525
sha256sum $x > ${x}.sha256
2626
done
@@ -29,7 +29,9 @@ jobs:
2929
uses: softprops/action-gh-release@v1
3030
with:
3131
files: |
32-
nixos-wsl-installer.tar.gz
33-
nixos-wsl-installer.tar.gz.sha256
32+
nixos-wsl.tar.gz
33+
nixos-wsl.tar.gz.sha256
34+
nixos-wsl-legacy.tar.gz
35+
nixos-wsl-legacy.tar.gz.sha256
3436
env:
3537
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
result
22
result-*
3-
nixos-wsl-installer.tar.gz
3+
nixos-wsl*.tar.gz

README.md

Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -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

1621
Then open up a Terminal, PowerShell or Command Prompt and run:
1722

1823
```sh
19-
wsl --import NixOS .\NixOS\ nixos-wsl-installer.tar.gz --version 2
24+
wsl --import NixOS .\NixOS\ nixos-wsl.tar.gz --version 2
2025
```
2126

2227
This 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
2429
downloaded earlier. You might need to change this path or change to the download directory first.
2530

2631
You can now run NixOS:
@@ -29,11 +34,6 @@ You can now run NixOS:
2934
wsl -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-
3737
If 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
6868
build 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

7474
Or, 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

8080
Without 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

9691
Getting 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

checks/username.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
let
88
baseModule = { ... }: {
9-
imports = [ ../configuration.nix ];
10-
9+
imports = [ ../modules ];
1110
wsl.enable = true;
11+
wsl.defaultUser = "nixos";
1212
};
1313
changedUsername = { lib, ... }: {
1414
wsl.defaultUser = lib.mkForce "different";

configuration.nix

Lines changed: 0 additions & 32 deletions
This file was deleted.

flake.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,48 @@
2626
};
2727
nixosModules.default = self.nixosModules.wsl;
2828

29-
nixosConfigurations.mysystem = nixpkgs.lib.nixosSystem {
30-
system = "x86_64-linux";
31-
modules = [
32-
./configuration.nix
33-
];
29+
nixosConfigurations = {
30+
modern = nixpkgs.lib.nixosSystem {
31+
system = "x86_64-linux";
32+
modules = [
33+
self.nixosModules.default
34+
{ wsl.enable = true; }
35+
];
36+
};
37+
38+
legacy = nixpkgs.lib.nixosSystem {
39+
system = "x86_64-linux";
40+
modules = [
41+
self.nixosModules.default
42+
{
43+
wsl.enable = true;
44+
wsl.nativeSystemd = false;
45+
}
46+
];
47+
};
48+
49+
test = nixpkgs.lib.nixosSystem {
50+
system = "x86_64-linux";
51+
modules = [
52+
self.nixosModules.default
53+
({ config, pkgs, ... }: {
54+
wsl.enable = true;
55+
wsl.nativeSystemd = false;
56+
57+
system.activationScripts.create-test-entrypoint.text =
58+
let
59+
syschdemdProxy = pkgs.writeShellScript "syschdemd-proxy" ''
60+
shell=$(${pkgs.glibc.bin}/bin/getent passwd root | ${pkgs.coreutils}/bin/cut -d: -f7)
61+
exec $shell $@
62+
'';
63+
in
64+
''
65+
mkdir -p /bin
66+
ln -sfn ${syschdemdProxy} /bin/syschdemd
67+
'';
68+
})
69+
];
70+
};
3471
};
3572

3673
} //

0 commit comments

Comments
 (0)