From 3daa1da497e4d167c2385f19b2a2d0df66876f23 Mon Sep 17 00:00:00 2001 From: Jaka Hudoklin Date: Fri, 24 May 2019 09:17:25 +0200 Subject: [PATCH] nixos: use usercfg.home.username for username Use `usercfg.home.username` for username instead of attribute name, as this way we can change username regardless of the name of the attribute. (cherry picked from commit 2e13c3cdfdb86e0d7dc0dd7a690db417714e4334) --- nixos/default.nix | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/nixos/default.nix b/nixos/default.nix index 5328e578..4628d1f2 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -60,28 +60,31 @@ in }) cfg.users ); - systemd.services = mapAttrs' (username: usercfg: - nameValuePair ("home-manager-${utils.escapeSystemdPath username}") { - description = "Home Manager environment for ${username}"; - wantedBy = [ "multi-user.target" ]; - wants = [ "nix-daemon.socket" ]; - after = [ "nix-daemon.socket" ]; + systemd.services = mapAttrs' (_: usercfg: + let + username = usercfg.home.username; + in + nameValuePair ("home-manager-${utils.escapeSystemdPath username}") { + description = "Home Manager environment for ${username}"; + wantedBy = [ "multi-user.target" ]; + wants = [ "nix-daemon.socket" ]; + after = [ "nix-daemon.socket" ]; - serviceConfig = { - User = usercfg.home.username; - Type = "oneshot"; - RemainAfterExit = "yes"; - SyslogIdentifier = "hm-activate-${username}"; + serviceConfig = { + User = usercfg.home.username; + Type = "oneshot"; + RemainAfterExit = "yes"; + SyslogIdentifier = "hm-activate-${username}"; - # The activation script is run by a login shell to make sure - # that the user is given a sane Nix environment. - ExecStart = pkgs.writeScript "activate-${username}" '' - #! ${pkgs.stdenv.shell} -el - echo Activating home-manager configuration for ${username} - exec ${usercfg.home.activationPackage}/activate - ''; - }; - } + # The activation script is run by a login shell to make sure + # that the user is given a sane Nix environment. + ExecStart = pkgs.writeScript "activate-${username}" '' + #! ${pkgs.stdenv.shell} -el + echo Activating home-manager configuration for ${username} + exec ${usercfg.home.activationPackage}/activate + ''; + }; + } ) cfg.users; }; }