refactor: buildClan output; output deferred modules instead of nixosConfig

This commit is contained in:
Johannes Kirschbauer
2025-04-15 13:17:28 +02:00
parent eb2639eb41
commit 14ace40820
2 changed files with 42 additions and 23 deletions

View File

@@ -2,9 +2,7 @@
system,
name,
pkgs,
extraConfig,
config,
clan-core,
clanConfiguration,
}:
{
_class,
@@ -12,8 +10,8 @@
...
}:
let
inherit (config) directory machines pkgsForSystem;
inherit (config.clanInternals) inventoryClass;
inherit (clanConfiguration) directory machines pkgsForSystem;
inherit (clanConfiguration.clanInternals) inventoryClass;
in
{
imports = [
@@ -29,13 +27,11 @@ in
);
}
(lib.optionalAttrs (_class == "nixos") {
imports = [
clan-core.nixosModules.clanCore
] ++ (inventoryClass.machines.${name}.machineImports or [ ]);
imports = (inventoryClass.machines.${name}.machineImports or [ ]);
config = {
clan.core.settings = {
inherit (config.inventory.meta) name icon;
inherit (clanConfiguration.inventory.meta) name icon;
inherit directory;
machine = {
@@ -46,8 +42,6 @@ in
# TODO: remove these
};
})
extraConfig
(machines.${name} or { })
(
{
networking.hostName = lib.mkDefault name;

View File

@@ -55,26 +55,24 @@ let
system ? null,
name,
pkgs ? null,
extraConfig ? { },
}:
nixpkgs.lib.nixosSystem {
modules =
let
module = lib.modules.importApply ./inner-module.nix {
innerModule = lib.modules.importApply ./inner-module.nix {
inherit
system
name
pkgs
extraConfig
config
clan-core
;
clanConfiguration = config;
};
in
[
module
(config.outputs.moduleForMachine.${name} or { })
innerModule
{
config.clan.core.module = module;
config.clan.core.module = innerModule;
}
];
@@ -88,19 +86,17 @@ let
system ? null,
name,
pkgs ? null,
extraConfig ? { },
}:
nix-darwin.lib.darwinSystem {
modules = [
(config.outputs.moduleForMachine.${name} or { })
(lib.modules.importApply ./inner-module.nix {
inherit
system
name
pkgs
extraConfig
config
clan-core
;
clanConfiguration = config;
})
];
@@ -110,7 +106,7 @@ let
};
};
allMachines = inventoryClass.machines;
allMachines = inventoryClass.machines; # <- inventory.machines <- clan.machines
machineClasses = lib.mapAttrs (
name: _: inventory.machines.${name}.machineClass or "nixos"
@@ -152,6 +148,35 @@ let
in
{
imports = [
{
options.outputs.moduleForMachine = lib.mkOption {
type = lib.types.attrsOf (
lib.types.deferredModuleWith {
staticModules = [
(
{ _class, ... }:
{
imports = lib.optionals (_class == "nixos") [
clan-core.nixosModules.clanCore
];
}
)
];
}
);
};
config.outputs.moduleForMachine = lib.mkMerge [
# Create one empty module for each machine such that there is a default for each machine
# See: 'staticModules' in the moduleForMachine option
# This is only necessary because clan.machines doesn't include all machines
# There can other sources: i.e. inventory
(lib.mapAttrs (_: _: { }) config.inventory.machines)
# The user can define some machine config here
# i.e. 'clan.machines.jon = ...'
config.machines
];
}
# Merge the inventory file
{
inventory = _: {