Merge pull request 'refactor: clan expose the clan module as is' (#4101) from hsjobeki/clan into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/4101
This commit is contained in:
@@ -11,45 +11,70 @@ let
|
|||||||
|
|
||||||
buildClanModule = clan-core.clanLib.buildClanModule;
|
buildClanModule = clan-core.clanLib.buildClanModule;
|
||||||
|
|
||||||
publicAttrs = import ../lib/modules/public.nix;
|
in
|
||||||
# Create output options only for listed attributes
|
{
|
||||||
# TODO: Refactor this into an explicit module, so we can have description and other attributes to be listed in flake-parts
|
# Backwards compatibility
|
||||||
outputModule = {
|
imports = [
|
||||||
clan = lib.genAttrs publicAttrs.clan (
|
(lib.mkRenamedOptionModule [ "clan" ] [ "flake" "clan" ])
|
||||||
name: config.clan.${name} or (throw "Output: clan.${name} not found.")
|
];
|
||||||
);
|
# Our module is completely public, so we dont need to map it
|
||||||
topLevel = {
|
# Mapped top level outputs
|
||||||
options = lib.genAttrs publicAttrs.topLevel (_: lib.mkOption { });
|
options.flake = {
|
||||||
config = lib.genAttrs publicAttrs.topLevel (
|
# Backwards compat
|
||||||
name: config.clan.${name} or (throw "Output: clan.${name} not found.")
|
clanInternals = lib.mkOption {
|
||||||
|
description = "Internals as used by the clan cli. Deprecated use clan.clanInternals";
|
||||||
|
visible = false;
|
||||||
|
readOnly = true;
|
||||||
|
default = config.flake.clan.clanInternals;
|
||||||
|
apply = lib.warn "Use clan.clanInternals instead";
|
||||||
|
};
|
||||||
|
# The one and only clan module
|
||||||
|
clan = lib.mkOption {
|
||||||
|
description = "The evaluated clan module";
|
||||||
|
default = { };
|
||||||
|
type = types.submoduleWith {
|
||||||
|
specialArgs = {
|
||||||
|
inherit clan-core self;
|
||||||
|
inherit (inputs) nixpkgs nix-darwin;
|
||||||
|
# TODO: inject the inventory interface
|
||||||
|
# inventoryInterface = {};
|
||||||
|
};
|
||||||
|
modules = [
|
||||||
|
buildClanModule.flakePartsModule
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
# Mapped flake toplevel outputs
|
||||||
|
darwinConfigurations = lib.mkOption {
|
||||||
|
type = types.lazyAttrsOf types.raw;
|
||||||
|
description = "darwinConfigurations produced by clan for a specific machine";
|
||||||
|
apply = lib.mapAttrs (
|
||||||
|
k: v: {
|
||||||
|
_file = "#nixosModules.${k}";
|
||||||
|
imports = [ v ];
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
darwinModules = lib.mkOption {
|
||||||
|
type = types.lazyAttrsOf types.deferredModule;
|
||||||
|
description = "darwinModules produced by clan for a specific machine";
|
||||||
|
apply = lib.mapAttrs (
|
||||||
|
k: v: {
|
||||||
|
_file = "#nixosModules.${k}";
|
||||||
|
imports = [ v ];
|
||||||
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
in
|
# Use normal prio, to allow merging with user values
|
||||||
{
|
config.flake = {
|
||||||
options.clan = lib.mkOption {
|
inherit (config.flake.clan)
|
||||||
default = { };
|
nixosConfigurations
|
||||||
type = types.submoduleWith {
|
nixosModules
|
||||||
specialArgs = {
|
darwinConfigurations
|
||||||
inherit clan-core self;
|
darwinModules
|
||||||
inherit (inputs) nixpkgs nix-darwin;
|
;
|
||||||
# TODO: inject the inventory interface
|
|
||||||
# inventoryInterface = {};
|
|
||||||
};
|
|
||||||
modules = [
|
|
||||||
buildClanModule.flakePartsModule
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
options.flake = {
|
|
||||||
clan = lib.mkOption { type = types.raw; };
|
|
||||||
} // outputModule.topLevel.options;
|
|
||||||
|
|
||||||
config = {
|
|
||||||
flake = {
|
|
||||||
clan = outputModule.clan;
|
|
||||||
} // outputModule.topLevel.config;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
_file = __curPos.file;
|
_file = __curPos.file;
|
||||||
|
|||||||
@@ -34,6 +34,7 @@
|
|||||||
Public attributes of buildClan. As specified in publicAttrs.
|
Public attributes of buildClan. As specified in publicAttrs.
|
||||||
*/
|
*/
|
||||||
buildClanWith =
|
buildClanWith =
|
||||||
|
|
||||||
{
|
{
|
||||||
clan-core,
|
clan-core,
|
||||||
# TODO: Below should be module options such that the user can override them?
|
# TODO: Below should be module options such that the user can override them?
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
self,
|
self,
|
||||||
self',
|
self',
|
||||||
|
lib,
|
||||||
pkgs,
|
pkgs,
|
||||||
flakeOptions,
|
flakeOptions,
|
||||||
...
|
...
|
||||||
@@ -23,7 +24,19 @@ let
|
|||||||
_module.args = { inherit (self) clanLib; };
|
_module.args = { inherit (self) clanLib; };
|
||||||
});
|
});
|
||||||
|
|
||||||
clanSchema = jsonLib.parseOptions (flakeOptions.clan.type.getSubOptions [ "clan" ]) { };
|
opts = (flakeOptions.flake.type.getSubOptions [ "flake" ]);
|
||||||
|
clanOpts = opts.clan.type.getSubOptions [ "clan" ];
|
||||||
|
include = [
|
||||||
|
"directory"
|
||||||
|
"inventory"
|
||||||
|
"machines"
|
||||||
|
"meta"
|
||||||
|
"modules"
|
||||||
|
"outputs"
|
||||||
|
"secrets"
|
||||||
|
"templates"
|
||||||
|
];
|
||||||
|
clanSchema = jsonLib.parseOptions (lib.filterAttrs (n: _v: lib.elem n include) clanOpts) { };
|
||||||
|
|
||||||
renderSchema = pkgs.writers.writePython3Bin "render-schema" {
|
renderSchema = pkgs.writers.writePython3Bin "render-schema" {
|
||||||
flakeIgnore = [
|
flakeIgnore = [
|
||||||
|
|||||||
@@ -187,8 +187,6 @@ ClanMetaType = Unknown
|
|||||||
ClanModulesType = dict[str, dict[str, Any] | list[Any] | bool | float | int | str | None]
|
ClanModulesType = dict[str, dict[str, Any] | list[Any] | bool | float | int | str | None]
|
||||||
ClanOutputsType = Output
|
ClanOutputsType = Output
|
||||||
ClanSecretsType = Secret
|
ClanSecretsType = Secret
|
||||||
ClanSelfType = dict[str, Any] | list[Any] | bool | float | int | str
|
|
||||||
ClanSpecialargsType = dict[str, dict[str, Any] | list[Any] | bool | float | int | str | None]
|
|
||||||
ClanTemplatesType = Template
|
ClanTemplatesType = Template
|
||||||
|
|
||||||
class Clan(TypedDict):
|
class Clan(TypedDict):
|
||||||
@@ -199,6 +197,4 @@ class Clan(TypedDict):
|
|||||||
modules: NotRequired[ClanModulesType]
|
modules: NotRequired[ClanModulesType]
|
||||||
outputs: NotRequired[ClanOutputsType]
|
outputs: NotRequired[ClanOutputsType]
|
||||||
secrets: NotRequired[ClanSecretsType]
|
secrets: NotRequired[ClanSecretsType]
|
||||||
self: NotRequired[ClanSelfType]
|
|
||||||
specialArgs: NotRequired[ClanSpecialargsType]
|
|
||||||
templates: NotRequired[ClanTemplatesType]
|
templates: NotRequired[ClanTemplatesType]
|
||||||
|
|||||||
Reference in New Issue
Block a user