Skip to content

Commit eb3e2d0

Browse files
committed
refactor(system): reuse parsed home configs
Parse home configuration metadata once while generating flake system outputs and pass matching homes into each system builder. Keep the existing fallback for direct mkSystem and mkDarwin callers.
1 parent 2aadb27 commit eb3e2d0

3 files changed

Lines changed: 41 additions & 17 deletions

File tree

flake/configs.nix

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,22 @@
55
...
66
}:
77
let
8-
inherit (self.lib.file) parseSystemConfigurations filterNixOSSystems filterDarwinSystems;
8+
inherit (self.lib.file)
9+
filterDarwinSystems
10+
filterNixOSSystems
11+
parseHomeConfigurations
12+
parseSystemConfigurations
13+
;
914

1015
systemsPath = ../systems;
16+
homesPath = ../homes;
1117
allSystems = parseSystemConfigurations systemsPath;
18+
allHomes = parseHomeConfigurations homesPath;
19+
matchingHomes =
20+
system: hostname:
21+
lib.filterAttrs (
22+
_name: homeConfig: homeConfig.system == system && homeConfig.hostname == hostname
23+
) allHomes;
1224
in
1325
{
1426
flake = {
@@ -20,6 +32,7 @@ in
2032
value = self.lib.system.mkSystem {
2133
inherit inputs system hostname;
2234
username = "khaneliman";
35+
matchingHomes = matchingHomes system hostname;
2336
};
2437
}
2538
) (filterNixOSSystems allSystems);
@@ -32,6 +45,7 @@ in
3245
value = self.lib.system.mkDarwin {
3346
inherit inputs system hostname;
3447
username = "khaneliman";
48+
matchingHomes = matchingHomes system hostname;
3549
};
3650
}
3751
) (filterDarwinSystems allSystems);

lib/system/mk-darwin.nix

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
system,
2525
hostname,
2626
username ? "khaneliman",
27+
matchingHomes ? null,
2728
modules ? [ ],
2829
...
2930
}:
@@ -35,22 +36,26 @@ let
3536
inputPackageSets = common.mkInputPackageSets {
3637
inherit flake system;
3738
};
38-
matchingHomes = common.mkHomeConfigs {
39-
inherit
40-
flake
41-
system
42-
hostname
43-
;
44-
};
39+
resolvedMatchingHomes =
40+
if matchingHomes == null then
41+
common.mkHomeConfigs {
42+
inherit
43+
flake
44+
system
45+
hostname
46+
;
47+
}
48+
else
49+
matchingHomes;
4550
homeManagerConfig = common.mkHomeManagerConfig {
4651
inherit
4752
extendedLib
4853
inputs
4954
system
5055
hostname
51-
matchingHomes
5256
inputPackageSets
5357
;
58+
matchingHomes = resolvedMatchingHomes;
5459
isNixOS = false;
5560
};
5661
in

lib/system/mk-system.nix

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
system,
2525
hostname,
2626
username ? "khaneliman",
27+
matchingHomes ? null,
2728
modules ? [ ],
2829
...
2930
}:
@@ -35,22 +36,26 @@ let
3536
inputPackageSets = common.mkInputPackageSets {
3637
inherit flake system;
3738
};
38-
matchingHomes = common.mkHomeConfigs {
39-
inherit
40-
flake
41-
system
42-
hostname
43-
;
44-
};
39+
resolvedMatchingHomes =
40+
if matchingHomes == null then
41+
common.mkHomeConfigs {
42+
inherit
43+
flake
44+
system
45+
hostname
46+
;
47+
}
48+
else
49+
matchingHomes;
4550
homeManagerConfig = common.mkHomeManagerConfig {
4651
inherit
4752
extendedLib
4853
inputs
4954
system
5055
hostname
51-
matchingHomes
5256
inputPackageSets
5357
;
58+
matchingHomes = resolvedMatchingHomes;
5459
isNixOS = true;
5560
};
5661
in

0 commit comments

Comments
 (0)