Merge pull request 'Feat(inventory): simplify instance module spec, by applying a default' (#4054) from hsjobeki/module-default into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/4054
This commit is contained in:
@@ -373,97 +373,106 @@ in
|
|||||||
instances = lib.mkOption {
|
instances = lib.mkOption {
|
||||||
description = "Multi host service module instances";
|
description = "Multi host service module instances";
|
||||||
type = types.attrsOf (
|
type = types.attrsOf (
|
||||||
types.submodule {
|
types.submoduleWith {
|
||||||
options = {
|
modules = [
|
||||||
# ModuleSpec
|
(
|
||||||
module = lib.mkOption {
|
{ name, ... }:
|
||||||
type = types.submodule {
|
{
|
||||||
options.input = lib.mkOption {
|
options = {
|
||||||
type = types.nullOr types.str;
|
# ModuleSpec
|
||||||
default = null;
|
module = lib.mkOption {
|
||||||
defaultText = "Name of the input. Default to 'null' which means the module is local";
|
type = types.submodule {
|
||||||
description = ''
|
options.input = lib.mkOption {
|
||||||
Name of the input. Default to 'null' which means the module is local
|
type = types.nullOr types.str;
|
||||||
'';
|
default = null;
|
||||||
};
|
defaultText = "Name of the input. Default to 'null' which means the module is local";
|
||||||
options.name = lib.mkOption {
|
description = ''
|
||||||
type = types.str;
|
Name of the input. Default to 'null' which means the module is local
|
||||||
};
|
'';
|
||||||
};
|
};
|
||||||
};
|
options.name = lib.mkOption {
|
||||||
roles = lib.mkOption {
|
type = types.str;
|
||||||
default = { };
|
default = name;
|
||||||
type = types.attrsOf (
|
};
|
||||||
types.submodule {
|
};
|
||||||
options = {
|
default = { };
|
||||||
# TODO: deduplicate
|
};
|
||||||
machines = lib.mkOption {
|
roles = lib.mkOption {
|
||||||
type = types.attrsOf (
|
default = { };
|
||||||
types.submodule {
|
type = types.attrsOf (
|
||||||
options.settings = lib.mkOption {
|
types.submodule {
|
||||||
|
options = {
|
||||||
|
# TODO: deduplicate
|
||||||
|
machines = lib.mkOption {
|
||||||
|
type = types.attrsOf (
|
||||||
|
types.submodule {
|
||||||
|
options.settings = lib.mkOption {
|
||||||
|
default = { };
|
||||||
|
type = clanLib.types.uniqueDeferredSerializableModule;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
default = { };
|
||||||
|
};
|
||||||
|
tags = lib.mkOption {
|
||||||
|
type = types.attrsOf (types.submodule { });
|
||||||
|
default = { };
|
||||||
|
};
|
||||||
|
settings = lib.mkOption {
|
||||||
default = { };
|
default = { };
|
||||||
type = clanLib.types.uniqueDeferredSerializableModule;
|
type = clanLib.types.uniqueDeferredSerializableModule;
|
||||||
};
|
};
|
||||||
}
|
extraModules = lib.mkOption {
|
||||||
);
|
description = ''
|
||||||
default = { };
|
List of additionally imported `.nix` expressions.
|
||||||
};
|
|
||||||
tags = lib.mkOption {
|
|
||||||
type = types.attrsOf (types.submodule { });
|
|
||||||
default = { };
|
|
||||||
};
|
|
||||||
settings = lib.mkOption {
|
|
||||||
default = { };
|
|
||||||
type = clanLib.types.uniqueDeferredSerializableModule;
|
|
||||||
};
|
|
||||||
extraModules = lib.mkOption {
|
|
||||||
description = ''
|
|
||||||
List of additionally imported `.nix` expressions.
|
|
||||||
|
|
||||||
Supported types:
|
Supported types:
|
||||||
|
|
||||||
- **Strings**: Interpreted relative to the 'directory' passed to buildClan.
|
- **Strings**: Interpreted relative to the 'directory' passed to buildClan.
|
||||||
- **Paths**: should be relative to the current file.
|
- **Paths**: should be relative to the current file.
|
||||||
- **Any**: Nix expression must be serializable to JSON.
|
- **Any**: Nix expression must be serializable to JSON.
|
||||||
|
|
||||||
!!! Note
|
!!! Note
|
||||||
**The import only happens if the machine is part of the service or role.**
|
**The import only happens if the machine is part of the service or role.**
|
||||||
|
|
||||||
Other types are passed through to the nixos configuration.
|
Other types are passed through to the nixos configuration.
|
||||||
|
|
||||||
???+ Example
|
???+ Example
|
||||||
To import the `special.nix` file
|
To import the `special.nix` file
|
||||||
|
|
||||||
```
|
```
|
||||||
. Clan Directory
|
. Clan Directory
|
||||||
├── flake.nix
|
├── flake.nix
|
||||||
...
|
...
|
||||||
└── modules
|
└── modules
|
||||||
├── special.nix
|
├── special.nix
|
||||||
└── ...
|
└── ...
|
||||||
```
|
```
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
{
|
{
|
||||||
extraModules = [ "modules/special.nix" ];
|
extraModules = [ "modules/special.nix" ];
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
'';
|
'';
|
||||||
apply = value: if lib.isString value then value else builtins.seq (builtins.toJSON value) value;
|
apply = value: if lib.isString value then value else builtins.seq (builtins.toJSON value) value;
|
||||||
default = [ ];
|
default = [ ];
|
||||||
type = types.listOf (
|
type = types.listOf (
|
||||||
types.oneOf [
|
types.oneOf [
|
||||||
types.str
|
types.str
|
||||||
types.path
|
types.path
|
||||||
(types.attrsOf types.anything)
|
(types.attrsOf types.anything)
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
);
|
}
|
||||||
};
|
)
|
||||||
};
|
];
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
default = { };
|
default = { };
|
||||||
|
|||||||
@@ -15,12 +15,12 @@ class Unknown:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
InventoryInstanceModuleNameType = str
|
|
||||||
InventoryInstanceModuleInputType = str
|
InventoryInstanceModuleInputType = str
|
||||||
|
InventoryInstanceModuleNameType = str
|
||||||
|
|
||||||
class InventoryInstanceModule(TypedDict):
|
class InventoryInstanceModule(TypedDict):
|
||||||
name: str
|
|
||||||
input: NotRequired[InventoryInstanceModuleInputType]
|
input: NotRequired[InventoryInstanceModuleInputType]
|
||||||
|
name: NotRequired[InventoryInstanceModuleNameType]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user