Merge pull request 'Inventory/tags: init {nixos,darwin} tags' (#3370) from hsjobeki/clan-core:tags-2 into main

Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/3370
This commit is contained in:
hsjobeki
2025-04-21 15:27:13 +00:00
3 changed files with 97 additions and 62 deletions

View File

@@ -1,33 +1,23 @@
{
config,
lib,
...
}:
{
config.inventory = {
# Add the computed tags to machine tags for displaying them
inventory = {
tags = (
{ machines, ... }:
{
# Only compute the default value
# The option MUST be defined in ./build-inventory/interface.nix
all = lib.mkDefault (builtins.attrNames machines);
}
nixos = lib.mkDefault (
builtins.attrNames (lib.filterAttrs (_n: m: m.machineClass == "nixos") machines)
);
};
# Add the computed tags to machine tags for displaying them
options.inventory = {
machines = lib.mkOption {
type = lib.types.attrsOf (
lib.types.submodule (
# 'name' is the machines attribute-name
{ name, ... }:
{
tags = builtins.attrNames (
lib.filterAttrs (_t: tagMembers: builtins.elem name tagMembers) config.inventory.tags
darwin = lib.mkDefault (
builtins.attrNames (lib.filterAttrs (_n: m: m.machineClass == "darwin") machines)
);
}
)
);
};
};
}

View File

@@ -223,6 +223,32 @@ in
```
'';
};
nixos = lib.mkOption {
type = with lib.types; listOf str;
defaultText = "[ <All NixOS Machines> ]";
description = ''
!!! example "Predefined Tag"
Will be added to all machines that set `machineClass = "darwin"`
```nix
inventory.machines.machineA.tags = [ "nixos" ];
```
'';
};
darwin = lib.mkOption {
type = with lib.types; listOf str;
defaultText = "[ <All Darwin Machines> ]";
description = ''
!!! example "Predefined Tag"
Will be added to all machines that set `machineClass = "darwin"`
```nix
inventory.machines.machineA.tags = [ "darwin" ];
```
'';
};
};
}
];
@@ -236,8 +262,19 @@ in
Each machine declared here can be referencd via its `attributeName` by the `inventory.service`s `roles`.
'';
default = { };
type = types.attrsOf (
types.submodule (
type = types.lazyAttrsOf (
types.submoduleWith ({
modules = [
(
{ name, ... }:
{
tags = builtins.attrNames (
# config.tags
lib.filterAttrs (_t: tagMembers: builtins.elem name tagMembers) config.tags
);
}
)
(
{ name, ... }:
{
options = {
@@ -288,6 +325,8 @@ in
};
}
)
];
})
);
};

View File

@@ -8,12 +8,18 @@ let
evalModules
;
# TODO: Use makeTestClan
evalInventory =
m:
(evalModules {
# Static modules
modules = [
clanLib.inventory.interface
{
tags.all = [ ];
tags.nixos = [ ];
tags.darwin = [ ];
}
{
modules.test = { };
}