systemd: do not install systemd files when user is root (#2454)
For the user root, there are no user services provided by systemd. Therefore, these files will never be used.
This commit is contained in:
parent
15ae861e1b
commit
c2aa831491
|
@ -258,7 +258,8 @@ in {
|
|||
|
||||
# If we run under a Linux system we assume that systemd is
|
||||
# available, in particular we assume that systemctl is in PATH.
|
||||
(mkIf pkgs.stdenv.isLinux {
|
||||
# Do not install any user services if username is root.
|
||||
(mkIf (pkgs.stdenv.isLinux && config.home.username != "root") {
|
||||
xdg.configFile = mkMerge [
|
||||
(lib.listToAttrs ((buildServices "service" cfg.services)
|
||||
++ (buildServices "slices" cfg.slices)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
systemd-services = ./services.nix;
|
||||
systemd-services-disabled-for-root = ./services-disabled-for-root.nix;
|
||||
systemd-session-variables = ./session-variables.nix;
|
||||
systemd-timers = ./timers.nix;
|
||||
}
|
||||
|
|
23
tests/modules/systemd/services-disabled-for-root.nix
Normal file
23
tests/modules/systemd/services-disabled-for-root.nix
Normal file
|
@ -0,0 +1,23 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
{
|
||||
config = {
|
||||
home.username = mkForce "root";
|
||||
|
||||
systemd.user.services."test-service@" = {
|
||||
Unit = { Description = "A basic test service"; };
|
||||
|
||||
Service = {
|
||||
Environment = [ "VAR1=1" "VAR2=2" ];
|
||||
ExecStart = ''/some/exec/start/command --with-arguments "%i"'';
|
||||
};
|
||||
};
|
||||
|
||||
nmt.script = ''
|
||||
serviceFile=home-files/.config/systemd/user/test-service@.service
|
||||
assertPathNotExists $serviceFile
|
||||
'';
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue