Skip to content

Commit

Permalink
fix systemd user sessions by launching through runuser
Browse files Browse the repository at this point in the history
  • Loading branch information
nzbr committed Oct 30, 2022
1 parent 136cc14 commit 8cfef03
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
3 changes: 3 additions & 0 deletions modules/wsl-distro.nix
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ with builtins; with lib;
enableEmergencyMode = false;
};

# Start a systemd user session when starting a command through runuser
security.pam.services.runuser.startSession = true;

warnings = (optional (config.systemd.services.systemd-resolved.enable && config.wsl.wslConf.network.generateResolvConf) "systemd-resolved is enabled, but resolv.conf is managed by WSL");
})
(mkIf (!cfg.nativeSystemd) {
Expand Down
3 changes: 1 addition & 2 deletions scripts/syschdemd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ mkWrappedScript {
glibc # getent
gnugrep
systemd # machinectl
util-linux # nsenter
util-linux # nsenter, runuser
wrapper
];
username = defaultUser.name;
uid = defaultUser.uid;
inherit automountPath;
}
3 changes: 1 addition & 2 deletions scripts/syschdemd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ main() {
run_in_namespace \
systemd-run \
--quiet \
--uid=@uid@ \
--collect \
--wait \
--pty \
Expand All @@ -135,7 +134,7 @@ main() {
--setenv=WSLPATH="$(clean_wslpath)" \
--working-directory="$PWD" \
--machine=.host \
/bin/sh -c "$exportCmd; source /etc/set-environment; exec $command"
"$(which runuser)" -u @username@ -- /bin/sh -c "$exportCmd; source /etc/set-environment; exec $command"
}

main "$@"

0 comments on commit 8cfef03

Please sign in to comment.