nixos: only refer to users.users if needed

Fixes a regression of GitHub issue #594. Before this commit,
attempting to dynamically configure Home Manager with contents of
nixos's users.users when using the nixos module would result in
infinite recursion.

PR #4368
This commit is contained in:
TNE 2023-08-21 19:55:03 +00:00 committed by Robert Helgesson
parent a0ad98174c
commit ca4126e3c5
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89

View file

@ -94,20 +94,23 @@ in {
}; };
}; };
config = mkIf (cfg.users != { }) { config = (mkMerge [
warnings = flatten (flip mapAttrsToList cfg.users (user: config: # Fix potential recursion when configuring home-manager users based on values in users.users #594
flip map config.warnings (warning: "${user} profile: ${warning}"))); (mkIf (cfg.useUserPackages && cfg.users != { }) {
users.users =
(mapAttrs (username: usercfg: { packages = [ usercfg.home.path ]; })
cfg.users);
environment.pathsToLink = [ "/etc/profile.d" ];
})
(mkIf (cfg.users != { }) {
warnings = flatten (flip mapAttrsToList cfg.users (user: config:
flip map config.warnings (warning: "${user} profile: ${warning}")));
assertions = flatten (flip mapAttrsToList cfg.users (user: config: assertions = flatten (flip mapAttrsToList cfg.users (user: config:
flip map config.assertions (assertion: { flip map config.assertions (assertion: {
inherit (assertion) assertion; inherit (assertion) assertion;
message = "${user} profile: ${assertion.message}"; message = "${user} profile: ${assertion.message}";
}))); })));
})
users.users = mkIf cfg.useUserPackages ]);
(mapAttrs (username: usercfg: { packages = [ usercfg.home.path ]; })
cfg.users);
environment.pathsToLink = mkIf cfg.useUserPackages [ "/etc/profile.d" ];
};
} }