1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-23 11:39:46 +01:00

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:
Tobias Happ 2021-11-23 07:06:43 +01:00 committed by GitHub
parent 15ae861e1b
commit c2aa831491
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 1 deletions

View file

@ -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)

View file

@ -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;
}

View 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
'';
};
}