Merge pull request #47842 from peterhoeg/f/activation
nixos system-activation: support activation scripts run in a user context
This commit is contained in:
commit
78289fc6f8
@ -225,11 +225,8 @@ in
|
|||||||
security.pam.services.sddm.enableKwallet = true;
|
security.pam.services.sddm.enableKwallet = true;
|
||||||
security.pam.services.slim.enableKwallet = true;
|
security.pam.services.slim.enableKwallet = true;
|
||||||
|
|
||||||
# Update the start menu for each user that has `isNormalUser` set.
|
# Update the start menu for each user that is currently logged in
|
||||||
system.activationScripts.plasmaSetup = stringAfter [ "users" "groups" ]
|
system.userActivationScripts.plasmaSetup = "${pkgs.libsForQt5.kservice}/bin/kbuildsycoca5";
|
||||||
(concatStringsSep "\n"
|
|
||||||
(mapAttrsToList (name: value: "${pkgs.su}/bin/su ${name} -c ${pkgs.libsForQt5.kservice}/bin/kbuildsycoca5")
|
|
||||||
(filterAttrs (n: v: v.isNormalUser) config.users.users)));
|
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -97,6 +97,52 @@ in
|
|||||||
# Prevent the current configuration from being garbage-collected.
|
# Prevent the current configuration from being garbage-collected.
|
||||||
ln -sfn /run/current-system /nix/var/nix/gcroots/current-system
|
ln -sfn /run/current-system /nix/var/nix/gcroots/current-system
|
||||||
|
|
||||||
|
exit $_status
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
system.userActivationScripts = mkOption {
|
||||||
|
default = {};
|
||||||
|
|
||||||
|
example = literalExample ''
|
||||||
|
{ plasmaSetup = {
|
||||||
|
text = '''
|
||||||
|
${pkgs.libsForQt5.kservice}/bin/kbuildsycoca5"
|
||||||
|
''';
|
||||||
|
deps = [];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
|
||||||
|
description = ''
|
||||||
|
A set of shell script fragments that are executed by a systemd user
|
||||||
|
service when a NixOS system configuration is activated. Examples are
|
||||||
|
rebuilding the .desktop file cache for showing applications in the menu.
|
||||||
|
Since these are executed every time you run
|
||||||
|
<command>nixos-rebuild</command>, it's important that they are
|
||||||
|
idempotent and fast.
|
||||||
|
'';
|
||||||
|
|
||||||
|
type = types.attrsOf types.unspecified;
|
||||||
|
|
||||||
|
apply = set: {
|
||||||
|
script = ''
|
||||||
|
unset PATH
|
||||||
|
for i in ${toString path}; do
|
||||||
|
PATH=$PATH:$i/bin:$i/sbin
|
||||||
|
done
|
||||||
|
|
||||||
|
_status=0
|
||||||
|
trap "_status=1 _localstatus=\$?" ERR
|
||||||
|
|
||||||
|
${
|
||||||
|
let
|
||||||
|
set' = mapAttrs (n: v: if isString v then noDepEntry v else v) set;
|
||||||
|
withHeadlines = addAttributeName set';
|
||||||
|
in textClosureMap id (withHeadlines) (attrNames withHeadlines)
|
||||||
|
}
|
||||||
|
|
||||||
exit $_status
|
exit $_status
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
@ -169,6 +215,14 @@ in
|
|||||||
source ${config.system.build.earlyMountScript}
|
source ${config.system.build.earlyMountScript}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
systemd.user = {
|
||||||
|
services.nixos-activation = {
|
||||||
|
description = "Run user specific NixOS activation";
|
||||||
|
script = config.system.userActivationScripts.script;
|
||||||
|
unitConfig.ConditionUser = "!@system";
|
||||||
|
serviceConfig.Type = "oneshot";
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -420,6 +420,7 @@ while (my $f = <$listActiveUsers>) {
|
|||||||
print STDERR "reloading user units for $name...\n";
|
print STDERR "reloading user units for $name...\n";
|
||||||
|
|
||||||
system("@su@", "-s", "@shell@", "-l", $name, "-c", "XDG_RUNTIME_DIR=/run/user/$uid @systemd@/bin/systemctl --user daemon-reload");
|
system("@su@", "-s", "@shell@", "-l", $name, "-c", "XDG_RUNTIME_DIR=/run/user/$uid @systemd@/bin/systemctl --user daemon-reload");
|
||||||
|
system("@su@", "-s", "@shell@", "-l", $name, "-c", "XDG_RUNTIME_DIR=/run/user/$uid @systemd@/bin/systemctl --user start nixos-activation.service");
|
||||||
}
|
}
|
||||||
|
|
||||||
close $listActiveUsers;
|
close $listActiveUsers;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user