Skip to content

Commit e8645a3

Browse files
authored
Merge pull request #64 from K900/main
binfmt / interop fixes
2 parents 0c4c599 + d7cf4b3 commit e8645a3

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

modules/wsl-distro.nix

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ with builtins; with lib;
2828
type = attrsOf (attrsOf coercedToStr);
2929
description = "Entries that are added to /etc/wsl.conf";
3030
};
31+
32+
interop = {
33+
register = mkOption {
34+
type = bool;
35+
default = true;
36+
description = "Explicitly register the binfmt_misc handler for Windows executables";
37+
};
38+
39+
includePath = mkOption {
40+
type = bool;
41+
default = true;
42+
description = "Include Windows PATH in WSL PATH";
43+
};
44+
};
3145
};
3246

3347
config =
@@ -47,12 +61,22 @@ with builtins; with lib;
4761
};
4862

4963
# WSL is closer to a container than anything else
50-
boot.isContainer = true;
64+
boot = {
65+
isContainer = true;
66+
67+
binfmt.registrations = mkIf cfg.interop.register {
68+
WSLInterop = {
69+
magicOrExtension = "MZ";
70+
interpreter = "/init";
71+
fixBinary = true;
72+
};
73+
};
74+
};
5175
environment.noXlibs = lib.mkForce false; # override xlibs not being installed (due to isContainer) to enable the use of GUI apps
5276

5377
environment = {
5478
# Include Windows %PATH% in Linux $PATH.
55-
extraInit = ''PATH="$PATH:$WSLPATH"'';
79+
extraInit = mkIf cfg.interop.includePath ''PATH="$PATH:$WSLPATH"'';
5680

5781
etc = {
5882
"wsl.conf".text = generators.toINI { } cfg.wslConf;

syschdemd.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@ pkgs.substituteAll {
1212
inherit defaultUser;
1313
inherit (config.security) wrapperDir;
1414
fsPackagesPath = lib.makeBinPath config.system.fsPackages;
15+
16+
systemdWrapper = pkgs.writeShellScript "systemd-wrapper.sh" ''
17+
mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc
18+
exec systemd
19+
'';
1520
}

syschdemd.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ if [ ! -e "/run/current-system" ]; then
1616
fi
1717

1818
if [ ! -e "/run/systemd.pid" ]; then
19+
@wrapperDir@/umount /proc/sys/fs/binfmt_misc
20+
1921
PATH=/run/current-system/systemd/lib/systemd:@fsPackagesPath@ \
2022
LOCALE_ARCHIVE=/run/current-system/sw/lib/locale/locale-archive \
21-
@daemonize@/bin/daemonize /run/current-system/sw/bin/unshare -fp --mount-proc systemd
23+
@daemonize@/bin/daemonize /run/current-system/sw/bin/unshare -fp --mount-proc @systemdWrapper@
2224
/run/current-system/sw/bin/pgrep -xf systemd >/run/systemd.pid
2325

2426
# Wait for systemd to start

0 commit comments

Comments
 (0)