Merge pull request 'feat(buildClan): expose {nixosModules,darwinModules} from clanInternals' (#3329) from hsjobeki/clan-core:lib-cleanup into main

Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/3329
This commit is contained in:
hsjobeki
2025-04-15 15:45:01 +00:00

View File

@@ -62,6 +62,8 @@ let
configurations = lib.mapAttrs ( configurations = lib.mapAttrs (
name: _: name: _:
moduleSystemConstructor.${machineClasses.${name}} { moduleSystemConstructor.${machineClasses.${name}} {
# ATTENTION!: Dont add any modules here.
# Add them to 'outputs.moduleForMachine.${name}' instead.
modules = [ (config.outputs.moduleForMachine.${name} or { }) ]; modules = [ (config.outputs.moduleForMachine.${name} or { }) ];
specialArgs = { specialArgs = {
inherit clan-core; inherit clan-core;
@@ -113,10 +115,10 @@ in
type = lib.types.attrsOf lib.types.deferredModule; type = lib.types.attrsOf lib.types.deferredModule;
}; };
config.outputs.moduleForMachine = lib.mkMerge [ config.outputs.moduleForMachine = lib.mkMerge [
# Create one empty module for each machine such that there is a default for each machine # Create some modules for each machine
# See: 'staticModules' in the moduleForMachine option # These can depend on the 'name' and
# This is only necessary because clan.machines doesn't include all machines # everything that can be derived from the machine 'name'
# There can other sources: i.e. inventory # i.e. by looking up the corresponding information in the 'inventory' or 'clan' submodule
(lib.mapAttrs ( (lib.mapAttrs (
name: v: name: v:
( (
@@ -173,10 +175,24 @@ in
./computed-tags.nix ./computed-tags.nix
]; ];
# Ready to use configurations
# These are only shallow wrapping the 'nixosModules' or 'darwinModules' with
# lib.nixosSystem
inherit nixosConfigurations; inherit nixosConfigurations;
inherit darwinConfigurations; inherit darwinConfigurations;
clanInternals = { clanInternals = {
# Expose reusable modules these can be imported or wrapped or instantiated
# - by the user
# - by some test frameworks
# IMPORTANT!: It is utterly important that we don't add any logic outside of these modules, as it would get tested.
nixosModules = lib.filterAttrs (
name: _: inventory.machines.${name}.machineClass or "nixos" == "nixos"
) (config.outputs.moduleForMachine);
darwinModules = lib.filterAttrs (
name: _: inventory.machines.${name}.machineClass or "nixos" == "darwin"
) (config.outputs.moduleForMachine);
moduleSchemas = clan-core.clanLib.modules.getModulesSchema { moduleSchemas = clan-core.clanLib.modules.getModulesSchema {
modules = config.inventory.modules; modules = config.inventory.modules;
# TODO: make this function system agnostic # TODO: make this function system agnostic