From e1c42210f92b0b7068547ebf492e4d254a08bc1f Mon Sep 17 00:00:00 2001 From: K900 Date: Sat, 26 Mar 2022 17:02:21 +0300 Subject: [PATCH] Allow disabling and customizing WSL-to-Windows interop - add an option to disable interop entirely - add an option to include Windows %PATH% in WSL $PATH - register interop through systemd-binfmt --- modules/wsl-distro.nix | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/modules/wsl-distro.nix b/modules/wsl-distro.nix index c2eb550f..825514df 100644 --- a/modules/wsl-distro.nix +++ b/modules/wsl-distro.nix @@ -28,6 +28,20 @@ with builtins; with lib; type = attrsOf (attrsOf coercedToStr); description = "Entries that are added to /etc/wsl.conf"; }; + + interop = { + enable = mkOption { + type = bool; + default = true; + description = "Enable running Windows executables from inside WSL"; + }; + + includePath = mkOption { + type = bool; + default = true; + description = "Include Windows PATH in WSL PATH"; + }; + }; }; config = @@ -47,12 +61,22 @@ with builtins; with lib; }; # WSL is closer to a container than anything else - boot.isContainer = true; + boot = { + isContainer = true; + + binfmt.registrations = mkIf cfg.interop.enable { + WSLInterop = { + magicOrExtension = "MZ"; + interpreter = "/init"; + fixBinary = true; + }; + }; + }; environment.noXlibs = lib.mkForce false; # override xlibs not being installed (due to isContainer) to enable the use of GUI apps environment = { # Include Windows %PATH% in Linux $PATH. - extraInit = ''PATH="$PATH:$WSLPATH"''; + extraInit = mkIf cfg.interop.includePath ''PATH="$PATH:$WSLPATH"''; etc = { "wsl.conf".text = generators.toINI { } cfg.wslConf;