refactor(buildClan): simplify pkgs overriding logic

This commit is contained in:
Johannes Kirschbauer
2025-04-15 16:05:57 +02:00
parent e68ab67112
commit 9800255a2c
3 changed files with 35 additions and 85 deletions

View File

@@ -1,26 +0,0 @@
{
pkgs,
pkgsForSystem,
system,
}:
{
lib,
...
}:
{
imports = [
(
{
# For vars we need to override the system so we run vars
# generators on the machine that runs `clan vars generate`. If a
# users is using the `pkgsForSystem`, we don't set
# nixpkgs.hostPlatform it would conflict with the `nixpkgs.pkgs`
# option.
nixpkgs.hostPlatform = lib.mkIf (system != null && (pkgsForSystem system) != null) (
lib.mkForce system
);
}
// lib.optionalAttrs (pkgs != null) { nixpkgs.pkgs = lib.mkForce pkgs; }
)
];
}

View File

@@ -0,0 +1,17 @@
{
pkgs,
}:
{
lib,
...
}:
{
imports = [
({
# For vars we need to ensure that the system so we run vars generate on
# is in sync with the pkgs of the system
nixpkgs.hostPlatform = lib.mkForce pkgs.system;
nixpkgs.pkgs = lib.mkForce pkgs;
})
];
}

View File

@@ -49,62 +49,8 @@ let
moduleSystemConstructor = {
# TODO: remove default system once we have a hardware-config mechanism
nixos =
{
system ? null,
name,
pkgs ? null,
}:
nixpkgs.lib.nixosSystem {
modules =
let
innerModule = lib.modules.importApply ./machineModules/forSystem.nix {
inherit
pkgs
pkgsForSystem
system
;
};
in
[
(config.outputs.moduleForMachine.${name} or { })
innerModule
{
config.clan.core.module = innerModule;
}
];
specialArgs = {
inherit clan-core;
} // specialArgs;
};
darwin =
{
system ? null,
name,
pkgs ? null,
}:
nix-darwin.lib.darwinSystem {
modules = [
(config.outputs.moduleForMachine.${name} or { })
# This module depends on the system and pkgs
# It contains optional logic to override 'nixpkgs.pkgs' and 'nixpkgs.hostPlatform'
# and other 'system' related logic
(lib.modules.importApply ./machineModules/forSystem.nix {
inherit
pkgs
pkgsForSystem
system
;
})
];
specialArgs = {
inherit clan-core;
} // specialArgs;
};
nixos = nixpkgs.lib.nixosSystem;
darwin = nix-darwin.lib.darwinSystem;
};
allMachines = inventoryClass.machines; # <- inventory.machines <- clan.machines
@@ -114,7 +60,13 @@ let
) allMachines;
configurations = lib.mapAttrs (
name: _: moduleSystemConstructor.${machineClasses.${name}} { inherit name; }
name: _:
moduleSystemConstructor.${machineClasses.${name}} {
modules = [ (config.outputs.moduleForMachine.${name} or { }) ];
specialArgs = {
inherit clan-core;
} // specialArgs;
}
) allMachines;
nixosConfigurations = lib.filterAttrs (name: _: machineClasses.${name} == "nixos") configurations;
@@ -130,8 +82,15 @@ let
lib.mapAttrs (
name: _:
moduleSystemConstructor.${machineClasses.${name}} {
inherit name system;
pkgs = pkgsFor.${system};
modules = [
(config.outputs.moduleForMachine.${name} or { })
(lib.modules.importApply ./machineModules/overridePkgs.nix {
pkgs = pkgsFor.${system};
})
];
specialArgs = {
inherit clan-core;
} // specialArgs;
}
) allMachines
)