Skip to content

Commit a18c84c

Browse files
authored
Merge pull request #93 from moduon/fix-double-pkgs-instancing
fix: don't reevaluate nixpkgs in nixosConfigurations
2 parents 76ff8fd + deee573 commit a18c84c

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

lib/default.nix

+24-4
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,30 @@ let
165165
;
166166

167167
# Adds the perSystem argument to the NixOS and Darwin modules
168+
perSystemArgsModule = system: {
169+
_module.args.perSystem = systemArgs.${system}.perSystem;
170+
};
171+
172+
# Shares pkgs with flake's, to avoid multiple nixpkgs reevaluations
168173
perSystemModule =
169-
{ pkgs, ... }:
174+
{ config, lib, ... }:
175+
{
176+
imports = [ (perSystemArgsModule config.nixpkgs.hostPlatform.system) ];
177+
nixpkgs.pkgs = lib.mkDefault systemArgs.${config.nixpkgs.hostPlatform.system}.pkgs;
178+
};
179+
180+
# Same thing for home-manager
181+
perSystemHMModule =
182+
{ osConfig, ... }:
170183
{
171-
_module.args.perSystem = systemArgs.${pkgs.system}.perSystem;
184+
imports = [ (perSystemArgsModule osConfig.nixpkgs.hostPlatform.system) ];
185+
};
186+
187+
# Same thing for system manager
188+
perSystemSMModule =
189+
{ config, lib, ... }:
190+
{
191+
imports = [ (perSystemArgsModule config.nixpkgs.hostPlatform) ];
172192
};
173193

174194
home-manager =
@@ -201,7 +221,7 @@ let
201221
{ perSystem, config, ... }:
202222
{
203223
imports = [ homeManagerModule ];
204-
home-manager.sharedModules = [ perSystemModule ];
224+
home-manager.sharedModules = [ perSystemHMModule ];
205225
home-manager.extraSpecialArgs = specialArgs;
206226
home-manager.users = homesNested.${hostname};
207227
home-manager.useGlobalPkgs = lib.mkDefault true;
@@ -352,7 +372,7 @@ let
352372
class = "system-manager";
353373
value = system-manager.lib.makeSystemConfig {
354374
modules = [
355-
perSystemModule
375+
perSystemSMModule
356376
path
357377
];
358378
extraSpecialArgs = specialArgs;

0 commit comments

Comments
 (0)