aboutsummaryrefslogtreecommitdiffhomepage
path: root/nixos.nix
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-06-07 04:29:32 +0900
committerOphestra <cat@gensokyo.uk>2025-06-08 01:12:18 +0900
commitbf5772bd8adfb844eb339c3e9d054bfde8ce955c (patch)
tree94acab50a89d1d7d223554c88c4d8caf2d255893 /nixos.nix
parent9a7c81a44e4876f2efde1e2d71a5ffbb0b3e96a8 (diff)
nix: deduplicate home-manager merging
This becomes a problem when extraHomeConfig defines nixos module options. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'nixos.nix')
-rw-r--r--nixos.nix62
1 files changed, 43 insertions, 19 deletions
diff --git a/nixos.nix b/nixos.nix
index 307355b2..25eb777a 100644
--- a/nixos.nix
+++ b/nixos.nix
@@ -9,6 +9,7 @@ packages:
let
inherit (lib)
lists
+ attrsets
mkMerge
mkIf
mapAttrs
@@ -231,25 +232,48 @@ in
{
useUserPackages = false; # prevent users.users entries from being added
- users = mkMerge (
- foldlAttrs (
- acc: _: fid:
- acc
- ++ foldlAttrs (
- acc': _: app:
- acc'
- ++ [
- {
- ${getsubname fid app.identity} = mkMerge [
- cfg.extraHomeConfig
- app.extraConfig
- { home.packages = app.packages; }
- ];
- }
- ]
- ) [ { ${getsubname fid 0} = cfg.extraHomeConfig; } ] cfg.apps
- ) [ privPackages ] cfg.users
- );
+ users =
+ mkMerge
+ (foldlAttrs
+ (
+ acc: _: fid:
+ foldlAttrs
+ (
+ acc: _: app:
+ (
+ let
+ key = getsubname fid app.identity;
+ in
+ {
+ usernames = acc.usernames // {
+ ${key} = true;
+ };
+ merge = acc.merge ++ [
+ {
+ ${key} = mkMerge (
+ [
+ app.extraConfig
+ { home.packages = app.packages; }
+ ]
+ ++ lib.optional (!attrsets.hasAttrByPath [ key ] acc.usernames) cfg.extraHomeConfig
+ );
+ }
+ ];
+ }
+ )
+ )
+ {
+ inherit (acc) usernames;
+ merge = acc.merge ++ [ { ${getsubname fid 0} = cfg.extraHomeConfig; } ];
+ }
+ cfg.apps
+ )
+ {
+ usernames = { };
+ merge = [ privPackages ];
+ }
+ cfg.users
+ ).merge;
};
users =