File tree 1 file changed +21
-1
lines changed
1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -67,8 +67,28 @@ with builtins; with lib;
67
67
binfmt . registrations = mkIf cfg . interop . register {
68
68
WSLInterop = {
69
69
magicOrExtension = "MZ" ;
70
- interpreter = "/init" ;
70
+
71
+ # FIXME: temporary hack for https://github.com/nix-community/NixOS-WSL/pull/84
72
+ #
73
+ # WSL Preview 0.58 and up registers the /init binfmt interp for Windows executable
74
+ # with the "preserve argv[0]" flag, so if you run `./foo.exe`, the interp gets invoked
75
+ # as `/init foo.exe ./foo.exe`.
76
+ # argv[0] --^ ^-- actual path
77
+ #
78
+ # Older versions expect to be called without the argv[0] bit, simply as `/init ./foo.exe`.
79
+ #
80
+ # We detect that by running `/init /known-not-existing-path.exe` and checking the exit code:
81
+ # the new style interp expects at least two arguments, so exits with exit code 1,
82
+ # presumably meaning "parsing error"; the old style interp attempts to actually run
83
+ # the executable, fails to find it, and exits with 255.
84
+ interpreter = pkgs . writeShellScript "nixos-wsl-binfmt-hack" ''
85
+ /init /nixos-wsl-does-not-exist.exe
86
+ [ $? -eq 255 ] && shift
87
+ exec /init $@
88
+ '' ;
89
+
71
90
fixBinary = true ;
91
+ preserveArgvZero = true ;
72
92
} ;
73
93
} ;
74
94
} ;
You can’t perform that action at this time.
0 commit comments