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

View File

@@ -55,26 +55,24 @@ let
system ? null, system ? null,
name, name,
pkgs ? null, pkgs ? null,
extraConfig ? { },
}: }:
nixpkgs.lib.nixosSystem { nixpkgs.lib.nixosSystem {
modules = modules =
let let
module = lib.modules.importApply ./inner-module.nix { innerModule = lib.modules.importApply ./inner-module.nix {
inherit inherit
system system
name name
pkgs pkgs
extraConfig
config
clan-core
; ;
clanConfiguration = config;
}; };
in 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, system ? null,
name, name,
pkgs ? null, pkgs ? null,
extraConfig ? { },
}: }:
nix-darwin.lib.darwinSystem { nix-darwin.lib.darwinSystem {
modules = [ modules = [
(config.outputs.moduleForMachine.${name} or { })
(lib.modules.importApply ./inner-module.nix { (lib.modules.importApply ./inner-module.nix {
inherit inherit
system system
name name
pkgs 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 ( machineClasses = lib.mapAttrs (
name: _: inventory.machines.${name}.machineClass or "nixos" name: _: inventory.machines.${name}.machineClass or "nixos"
@@ -152,6 +148,35 @@ let
in in
{ {
imports = [ 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 # Merge the inventory file
{ {
inventory = _: { inventory = _: {