summaryrefslogtreecommitdiff
path: root/modules/interop.nix
diff options
context:
space:
mode:
authornzbr <mail@nzbr.de>2023-09-29 23:25:53 +0200
committerGitHub <noreply@github.com>2023-09-29 23:25:53 +0200
commit8735bdfa5fdfa6e90d944ff9f5f806668b53eacb (patch)
tree64148d00bbc6f8e1d7ba099cfbf31123113db2f8 /modules/interop.nix
parente7d93d0f478b6fbb47c00d03449dc3d08b90abb7 (diff)
parentff1413aa34c525bf01145b40b99acfb7868ab285 (diff)
Merge pull request #295 from nix-community/prep-release
New release preparation
Diffstat (limited to 'modules/interop.nix')
-rw-r--r--modules/interop.nix58
1 files changed, 8 insertions, 50 deletions
diff --git a/modules/interop.nix b/modules/interop.nix
index d055d4b..bcd3040 100644
--- a/modules/interop.nix
+++ b/modules/interop.nix
@@ -1,11 +1,7 @@
-{ lib, pkgs, config, ... }:
+{ lib, config, ... }:
with builtins; with lib;
{
- imports = [
- (mkRenamedOptionModule [ "wsl" "compatibility" "interopPreserveArgvZero" ] [ "wsl" "interop" "preserveArgvZero" ])
- ];
-
options.wsl.interop = with types; {
register = mkOption {
type = bool;
@@ -18,18 +14,6 @@ with builtins; with lib;
default = true;
description = "Include Windows PATH in WSL PATH";
};
-
- preserveArgvZero = mkOption {
- type = nullOr bool;
- default = null;
- description = ''
- Register binfmt interpreter for Windows executables with 'preserves argv[0]' flag.
-
- Default (null): autodetect, at some performance cost.
- To avoid the performance cost, set this to true for WSL Preview 0.58 and up,
- or to false for any older versions, including pre-Microsoft Store and Windows 10.
- '';
- };
};
config =
@@ -39,39 +23,13 @@ with builtins; with lib;
mkIf config.wsl.enable {
boot.binfmt.registrations = mkIf cfg.register {
- WSLInterop =
- let
- compat = cfg.preserveArgvZero;
-
- # WSL Preview 0.58 and up registers the /init binfmt interp for Windows executable
- # with the "preserve argv[0]" flag, so if you run `./foo.exe`, the interp gets invoked
- # as `/init foo.exe ./foo.exe`.
- # argv[0] --^ ^-- actual path
- #
- # Older versions expect to be called without the argv[0] bit, simply as `/init ./foo.exe`.
- #
- # We detect that by running `/init /known-not-existing-path.exe` and checking the exit code:
- # the new style interp expects at least two arguments, so exits with exit code 1,
- # presumably meaning "parsing error"; the old style interp attempts to actually run
- # the executable, fails to find it, and exits with 255.
- compatWrapper = pkgs.writeShellScript "nixos-wsl-binfmt-hack" ''
- /init /nixos-wsl-does-not-exist.exe
- [ $? -eq 255 ] && shift
- exec /init "$@"
- '';
-
- # use the autodetect hack if unset, otherwise call /init directly
- interpreter = if compat == null then compatWrapper else "/init";
-
- # enable for the wrapper and autodetect hack
- preserveArgvZero = if compat == false then false else true;
- in
- {
- magicOrExtension = "MZ";
- fixBinary = true;
- wrapInterpreterInShell = false;
- inherit interpreter preserveArgvZero;
- };
+ WSLInterop = {
+ magicOrExtension = "MZ";
+ fixBinary = true;
+ wrapInterpreterInShell = false;
+ interpreter = "/init";
+ preserveArgvZero = true;
+ };
};
warnings =