Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use internal WSL knobs instead of symlinks #281

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions modules/wsl-conf.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ with lib; {
default = false;
description = "Use systemd as init. There's no need to enable this manually, use the wsl.nativeSystemd option instead";
};
initPath = mkOption {
type = path;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this need to be nullOr path?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, I haven't actually tested this on non-native-systemd yet.

default = null;
internal = true;
};
initShutdownCommand = mkOption {
type = path;
default = null;
internal = true;
};
initWaitCommand = mkOption {
type = path;
default = null;
internal = true;
};
};
interop = {
enabled = mkOption {
Expand Down
24 changes: 12 additions & 12 deletions modules/wsl-distro.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
with lib;

let
bashWrapper = pkgs.writeShellScriptBin "sh" ''
export PATH="$PATH:${lib.makeBinPath [ pkgs.systemd pkgs.gnugrep ]}"
exec ${pkgs.bashInteractive}/bin/sh "$@"
'';

nixos-enter' = config.system.build.nixos-enter.overrideAttrs (_: {
runtimeShell = "/bin/bash";
});
Expand Down Expand Up @@ -176,7 +171,7 @@ in

# require people to use lib.mkForce to make it harder to brick their installation
wsl = {
binShPkg = if cfg.nativeSystemd then bashWrapper else pkgs.bashInteractive;
binShPkg = pkgs.bashInteractive;
populateBin = true;
};

Expand Down Expand Up @@ -211,15 +206,20 @@ in
(mkIf cfg.nativeSystemd {
wsl.wslConf = {
user.default = config.users.users.${cfg.defaultUser}.name;
boot.systemd = true;
boot = {
systemd = true;
initPath = "${nativeUtils}/bin/systemd-shim";
initShutdownCommand = pkgs.writeShellScript "nixos-wsl-init-shutdown" ''
${pkgs.systemd}/bin/systemctl reboot
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
${pkgs.systemd}/bin/systemctl reboot
${pkgs.systemd}/bin/systemctl reboot "$@"

just incase

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually pretty sure we can avoid the shell script here and just write the string directly.

'';
initWaitCommand = pkgs.writeShellScript "nixos-wsl-init-wait" ''
${pkgs.systemd}/bin/systemctl is-system-running | ${pkgs.gnugrep}/bin/grep -E "(running|degraded)"
exit $?
'';
};
};

system.activationScripts = {
shimSystemd = stringAfter [ ] ''
echo "setting up /sbin/init shim..."
mkdir -p /sbin
ln -sf ${nativeUtils}/bin/systemd-shim /sbin/init
'';
setupLogin = lib.mkIf cfg.populateBin (stringAfter [ ] ''
echo "setting up /bin/login..."
mkdir -p /bin
Expand Down
Loading