File tree Expand file tree Collapse file tree 3 files changed +34
-3
lines changed Expand file tree Collapse file tree 3 files changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,20 @@ with builtins; with lib;
28
28
type = attrsOf ( attrsOf coercedToStr ) ;
29
29
description = "Entries that are added to /etc/wsl.conf" ;
30
30
} ;
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
+ } ;
31
45
} ;
32
46
33
47
config =
@@ -47,12 +61,22 @@ with builtins; with lib;
47
61
} ;
48
62
49
63
# 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
+ } ;
51
75
environment . noXlibs = lib . mkForce false ; # override xlibs not being installed (due to isContainer) to enable the use of GUI apps
52
76
53
77
environment = {
54
78
# Include Windows %PATH% in Linux $PATH.
55
- extraInit = ''PATH="$PATH:$WSLPATH"'' ;
79
+ extraInit = mkIf cfg . interop . includePath ''PATH="$PATH:$WSLPATH"'' ;
56
80
57
81
etc = {
58
82
"wsl.conf" . text = generators . toINI { } cfg . wslConf ;
Original file line number Diff line number Diff line change @@ -12,4 +12,9 @@ pkgs.substituteAll {
12
12
inherit defaultUser ;
13
13
inherit ( config . security ) wrapperDir ;
14
14
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
+ '' ;
15
20
}
Original file line number Diff line number Diff line change @@ -16,9 +16,11 @@ if [ ! -e "/run/current-system" ]; then
16
16
fi
17
17
18
18
if [ ! -e " /run/systemd.pid" ]; then
19
+ @wrapperDir@/umount /proc/sys/fs/binfmt_misc
20
+
19
21
PATH=/run/current-system/systemd/lib/systemd:@fsPackagesPath@ \
20
22
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@
22
24
/run/current-system/sw/bin/pgrep -xf systemd > /run/systemd.pid
23
25
24
26
# Wait for systemd to start
You can’t perform that action at this time.
0 commit comments