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:
@@ -1,33 +1,23 @@
|
|||||||
{
|
{
|
||||||
config,
|
|
||||||
lib,
|
lib,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
{
|
{
|
||||||
config.inventory = {
|
# Add the computed tags to machine tags for displaying them
|
||||||
|
inventory = {
|
||||||
tags = (
|
tags = (
|
||||||
{ machines, ... }:
|
{ machines, ... }:
|
||||||
{
|
{
|
||||||
# Only compute the default value
|
# Only compute the default value
|
||||||
# The option MUST be defined in ./build-inventory/interface.nix
|
# The option MUST be defined in ./build-inventory/interface.nix
|
||||||
all = lib.mkDefault (builtins.attrNames machines);
|
all = lib.mkDefault (builtins.attrNames machines);
|
||||||
|
nixos = lib.mkDefault (
|
||||||
|
builtins.attrNames (lib.filterAttrs (_n: m: m.machineClass == "nixos") machines)
|
||||||
|
);
|
||||||
|
darwin = lib.mkDefault (
|
||||||
|
builtins.attrNames (lib.filterAttrs (_n: m: m.machineClass == "darwin") 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
|
|
||||||
);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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`.
|
Each machine declared here can be referencd via its `attributeName` by the `inventory.service`s `roles`.
|
||||||
'';
|
'';
|
||||||
default = { };
|
default = { };
|
||||||
type = types.attrsOf (
|
type = types.lazyAttrsOf (
|
||||||
types.submodule (
|
types.submoduleWith ({
|
||||||
|
modules = [
|
||||||
|
(
|
||||||
|
{ name, ... }:
|
||||||
|
{
|
||||||
|
tags = builtins.attrNames (
|
||||||
|
# config.tags
|
||||||
|
lib.filterAttrs (_t: tagMembers: builtins.elem name tagMembers) config.tags
|
||||||
|
);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
(
|
||||||
{ name, ... }:
|
{ name, ... }:
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
@@ -288,6 +325,8 @@ in
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
];
|
||||||
|
})
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -8,12 +8,18 @@ let
|
|||||||
evalModules
|
evalModules
|
||||||
;
|
;
|
||||||
|
|
||||||
|
# TODO: Use makeTestClan
|
||||||
evalInventory =
|
evalInventory =
|
||||||
m:
|
m:
|
||||||
(evalModules {
|
(evalModules {
|
||||||
# Static modules
|
# Static modules
|
||||||
modules = [
|
modules = [
|
||||||
clanLib.inventory.interface
|
clanLib.inventory.interface
|
||||||
|
{
|
||||||
|
tags.all = [ ];
|
||||||
|
tags.nixos = [ ];
|
||||||
|
tags.darwin = [ ];
|
||||||
|
}
|
||||||
{
|
{
|
||||||
modules.test = { };
|
modules.test = { };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user