Fix process quitting for sudo processes

This commit is contained in:
Manuel Thalmann 2024-05-01 04:40:38 +02:00
parent 7f862474b4
commit c6c793b3f3

View file

@ -122,37 +122,42 @@ in {
vm
else
let
command = "${vm}/bin/run-${config.system.name}-vm";
prefix =
lib.concatStringsSep " " (
lib.optionals config.virtualisation.runAsRoot (
["sudo"] ++
lib.optional config.virtualisation.qemu.runInBackground "-b"));
originalCommand = "${vm}/bin/run-${config.system.name}-vm";
suffix =
lib.concatStringsSep " " (
lib.optional
(!config.virtualisation.runAsRoot && config.virtualisation.qemu.runInBackground)
"&");
lib.optional config.virtualisation.qemu.runInBackground "&");
wrapped = pkgs.writeShellApplication {
shellApp = pkgs.writeShellApplication {
name = "run-${config.system.name}-vm";
text = lib.strings.concatLines (
[
"${prefix} ${command} ${suffix}"
"${originalCommand} ${suffix}"
] ++ (
let
spice = config.virtualisation.qemu.spice;
viewerPrefix = "sudo -Eu\"#$SUDO_UID\" ";
in
(
lib.optionals
config.virtualisation.virt-viewer
[
"${pkgs.virt-viewer}/bin/remote-viewer spice://${lib.escapeShellArg spice.bindAddress}:${toString spice.port}"
"${viewerPrefix}${pkgs.virt-viewer}/bin/remote-viewer spice://${lib.escapeShellArg spice.bindAddress}:${toString spice.port}"
"kill %1"
])));
};
wrapped =
if !config.virtualisation.runAsRoot
then
shellApp
else
pkgs.writeShellApplication {
name = shellApp.name;
text = ''
sudo -E ${shellApp}/bin/${shellApp.name}
'';
};
in
pkgs.symlinkJoin {
name = packageName;