Merge pull request 'clan/inventory: allow list usage of roles via polymorphism' (#4918) from cleanup-again into main

Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/4918
This commit is contained in:
hsjobeki
2025-08-25 10:41:49 +00:00
6 changed files with 12 additions and 17 deletions

View File

@@ -46,7 +46,7 @@
ln -sfT ${inputs.nix-select} "$PRJ_ROOT/pkgs/clan-cli/clan_lib/select"
# Generate classes.py from schemas
${self'.packages.classgen}/bin/classgen ${self'.legacyPackages.schemas.clan-schema-abstract}/schema.json $PRJ_ROOT/pkgs/clan-cli/clan_lib/nix_models/clan.py
${self'.packages.classgen}/bin/classgen ${self'.legacyPackages.schemas.clanSchemaJson}/schema.json $PRJ_ROOT/pkgs/clan-cli/clan_lib/nix_models/clan.py
'';
};
};

View File

@@ -21,14 +21,14 @@ let
"secrets"
"templates"
];
clanSchema = jsonLib.parseOptions (lib.filterAttrs (n: _v: lib.elem n include) clanOpts) { };
clanSchemaNix = jsonLib.parseOptions (lib.filterAttrs (n: _v: lib.elem n include) clanOpts) { };
clan-schema-abstract = pkgs.stdenv.mkDerivation {
clanSchemaJson = pkgs.stdenv.mkDerivation {
name = "clan-schema-files";
buildInputs = [ pkgs.cue ];
src = ./.;
buildPhase = ''
export SCHEMA=${builtins.toFile "clan-schema.json" (builtins.toJSON clanSchema)}
export SCHEMA=${builtins.toFile "clan-schema.json" (builtins.toJSON clanSchemaNix)}
cp $SCHEMA schema.json
# Also generate a CUE schema version that is derived from the JSON schema
cue import -f -p compose -l '#Root:' schema.json
@@ -41,7 +41,7 @@ in
{
inherit
flakeOptions
clanSchema
clan-schema-abstract
clanSchemaNix
clanSchemaJson
;
}

View File

@@ -27,7 +27,9 @@ in
default = { };
};
tags = lib.mkOption {
type = types.attrsOf (types.submodule { });
type = types.coercedTo (types.listOf types.str) (t: lib.genAttrs t (_: { })) (
types.attrsOf (types.submodule { })
);
default = { };
};
settings =

View File

@@ -31,17 +31,10 @@ class InventoryInstanceRoleMachine(TypedDict):
class InventoryInstanceRoleTag(TypedDict):
pass
InventoryInstanceRoleExtramodulesType = list[dict[str, Any] | str]
InventoryInstanceRoleMachinesType = dict[str, InventoryInstanceRoleMachine]
InventoryInstanceRoleSettingsType = Unknown
InventoryInstanceRoleTagsType = dict[str, InventoryInstanceRoleTag]
InventoryInstanceRoleTagsType = dict[str, Any] | list[str]
class InventoryInstanceRole(TypedDict):
extraModules: NotRequired[InventoryInstanceRoleExtramodulesType]

View File

@@ -2,7 +2,7 @@
set -euo pipefail
clanSchema=$(nix build .#schemas.clan-schema-abstract --print-out-paths)/schema.json
clanSchema=$(nix build .#schemas.clanSchemaJson --print-out-paths)/schema.json
SCRIPT_DIR=$(dirname "$0")
cd "$SCRIPT_DIR"
nix run .#classgen -- "$clanSchema" "./clan.py"

View File

@@ -134,7 +134,7 @@
classFile = "clan.py";
};
installPhase = ''
${self'.packages.classgen}/bin/classgen ${self'.legacyPackages.schemas.clan-schema-abstract}/schema.json b_classes.py
${self'.packages.classgen}/bin/classgen ${self'.legacyPackages.schemas.clanSchemaJson}/schema.json b_classes.py
file1=$classFile
file2=b_classes.py