Skip to content

Commit

Permalink
Merge pull request #64 from K900/main
Browse files Browse the repository at this point in the history
binfmt / interop fixes
  • Loading branch information
nzbr authored Mar 30, 2022
2 parents 0c4c599 + d7cf4b3 commit e8645a3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 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.register {
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
5 changes: 5 additions & 0 deletions syschdemd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ pkgs.substituteAll {
inherit defaultUser;
inherit (config.security) wrapperDir;
fsPackagesPath = lib.makeBinPath config.system.fsPackages;

systemdWrapper = pkgs.writeShellScript "systemd-wrapper.sh" ''
mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc
exec systemd
'';
}
4 changes: 3 additions & 1 deletion syschdemd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ if [ ! -e "/run/current-system" ]; then
fi

if [ ! -e "/run/systemd.pid" ]; then
@wrapperDir@/umount /proc/sys/fs/binfmt_misc

PATH=/run/current-system/systemd/lib/systemd:@fsPackagesPath@ \
LOCALE_ARCHIVE=/run/current-system/sw/lib/locale/locale-archive \
@daemonize@/bin/daemonize /run/current-system/sw/bin/unshare -fp --mount-proc systemd
@daemonize@/bin/daemonize /run/current-system/sw/bin/unshare -fp --mount-proc @systemdWrapper@
/run/current-system/sw/bin/pgrep -xf systemd >/run/systemd.pid

# Wait for systemd to start
Expand Down

0 comments on commit e8645a3

Please sign in to comment.