Skip to content

Commit

Permalink
Allow disabling and customizing WSL-to-Windows interop
Browse files Browse the repository at this point in the history
- add an option to disable interop entirely
- add an option to include Windows %PATH% in WSL $PATH
- register interop through systemd-binfmt
  • Loading branch information
K900 committed Mar 30, 2022
1 parent 8d7840d commit 0b226ee
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions modules/wsl-distro.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ with builtins; with lib;
type = attrsOf (attrsOf coercedToStr);
description = "Entries that are added to /etc/wsl.conf";
};

interop = {
register = mkOption {
type = bool;
default = true;
description = "Explicitly register the binfmt_misc handler for Windows executables";
};

includePath = mkOption {
type = bool;
default = true;
description = "Include Windows PATH in WSL PATH";
};
};
};

config =
Expand All @@ -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;
Expand Down

0 comments on commit 0b226ee

Please sign in to comment.