Merge pull request 'inventory/interface: reduce apply arguments chain by adding options' (#4092) from clan-unify into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/4092
This commit is contained in:
@@ -121,9 +121,10 @@
|
|||||||
roleName: roleSettingsModule:
|
roleName: roleSettingsModule:
|
||||||
mkOption {
|
mkOption {
|
||||||
type = types.submodule {
|
type = types.submodule {
|
||||||
|
_file = "docs flake-module";
|
||||||
imports = [
|
imports = [
|
||||||
|
{ _module.args = { inherit clanLib; }; }
|
||||||
(import ../../../lib/inventory/build-inventory/roles-interface.nix {
|
(import ../../../lib/inventory/build-inventory/roles-interface.nix {
|
||||||
inherit clanLib;
|
|
||||||
nestedSettingsOption = mkOption {
|
nestedSettingsOption = mkOption {
|
||||||
type = types.raw;
|
type = types.raw;
|
||||||
description = ''
|
description = ''
|
||||||
@@ -148,10 +149,12 @@
|
|||||||
mkScope = name: modules: {
|
mkScope = name: modules: {
|
||||||
inherit name;
|
inherit name;
|
||||||
modules = [
|
modules = [
|
||||||
(import ../../../lib/inventory/build-inventory/interface.nix {
|
{
|
||||||
inherit clanLib;
|
_module.args = { inherit clanLib; };
|
||||||
noInstanceOptions = true;
|
_file = "docs mkScope";
|
||||||
})
|
}
|
||||||
|
{ noInstanceOptions = true; }
|
||||||
|
../../../lib/inventory/build-inventory/interface.nix
|
||||||
] ++ mapAttrsToList fakeInstanceOptions modules;
|
] ++ mapAttrsToList fakeInstanceOptions modules;
|
||||||
urlPrefix = "https://github.com/nix-community/dream2nix/blob/main/";
|
urlPrefix = "https://github.com/nix-community/dream2nix/blob/main/";
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -170,6 +170,7 @@ in
|
|||||||
getRoleFile = role: builtins.seq role inventory.modules.${serviceName} + "/roles/${role}.nix";
|
getRoleFile = role: builtins.seq role inventory.modules.${serviceName} + "/roles/${role}.nix";
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
_file = "inventory/builder.nix";
|
||||||
_module.args = {
|
_module.args = {
|
||||||
inherit
|
inherit
|
||||||
resolveTags
|
resolveTags
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
{
|
|
||||||
clanLib,
|
|
||||||
# workaround for docs rendering to include fake instance options
|
|
||||||
noInstanceOptions ? false,
|
|
||||||
}:
|
|
||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
|
clanLib,
|
||||||
config,
|
config,
|
||||||
options,
|
options,
|
||||||
...
|
...
|
||||||
@@ -101,6 +97,7 @@ in
|
|||||||
./assertions.nix
|
./assertions.nix
|
||||||
];
|
];
|
||||||
options = {
|
options = {
|
||||||
|
# Internal things
|
||||||
_inventoryFile = lib.mkOption {
|
_inventoryFile = lib.mkOption {
|
||||||
type = types.path;
|
type = types.path;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
@@ -112,6 +109,12 @@ in
|
|||||||
visible = false;
|
visible = false;
|
||||||
default = { };
|
default = { };
|
||||||
};
|
};
|
||||||
|
noInstanceOptions = lib.mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
internal = true;
|
||||||
|
visible = false;
|
||||||
|
default = false;
|
||||||
|
};
|
||||||
|
|
||||||
options = lib.mkOption {
|
options = lib.mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
@@ -119,6 +122,8 @@ in
|
|||||||
type = types.raw;
|
type = types.raw;
|
||||||
default = options;
|
default = options;
|
||||||
};
|
};
|
||||||
|
# ---------------------------
|
||||||
|
|
||||||
modules = lib.mkOption {
|
modules = lib.mkOption {
|
||||||
# Don't define the type yet
|
# Don't define the type yet
|
||||||
# We manually transform the value with types.deferredModule.merge later to keep them serializable
|
# We manually transform the value with types.deferredModule.merge later to keep them serializable
|
||||||
@@ -375,7 +380,7 @@ in
|
|||||||
};
|
};
|
||||||
|
|
||||||
instances =
|
instances =
|
||||||
if noInstanceOptions then
|
if config.noInstanceOptions then
|
||||||
{ }
|
{ }
|
||||||
else
|
else
|
||||||
lib.mkOption {
|
lib.mkOption {
|
||||||
@@ -414,7 +419,15 @@ in
|
|||||||
default = { };
|
default = { };
|
||||||
type = types.attrsOf (
|
type = types.attrsOf (
|
||||||
types.submodule {
|
types.submodule {
|
||||||
imports = [ (import ./roles-interface.nix { inherit clanLib; }) ];
|
imports = [
|
||||||
|
{
|
||||||
|
_file = "inventory/interface";
|
||||||
|
_module.args = {
|
||||||
|
inherit clanLib;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
(import ./roles-interface.nix { })
|
||||||
|
];
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
{
|
{
|
||||||
clanLib,
|
|
||||||
settingsOption ? null,
|
settingsOption ? null,
|
||||||
nestedSettingsOption ? null,
|
nestedSettingsOption ? null,
|
||||||
}:
|
}:
|
||||||
{ lib, ... }:
|
{ lib, clanLib, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib)
|
inherit (lib)
|
||||||
types
|
types
|
||||||
|
|||||||
@@ -6,12 +6,11 @@ in
|
|||||||
inherit (services) evalClanService mapInstances resolveModule;
|
inherit (services) evalClanService mapInstances resolveModule;
|
||||||
inherit (import ./build-inventory { inherit lib clanLib; }) buildInventory;
|
inherit (import ./build-inventory { inherit lib clanLib; }) buildInventory;
|
||||||
interface = {
|
interface = {
|
||||||
|
_file = "inventory/default.nix";
|
||||||
imports = [
|
imports = [
|
||||||
(import ./build-inventory/interface.nix { inherit clanLib; })
|
./build-inventory/interface.nix
|
||||||
];
|
];
|
||||||
_module.args = {
|
_module.args = { inherit clanLib; };
|
||||||
inherit clanLib;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
# Returns the list of machine names
|
# Returns the list of machine names
|
||||||
# { ... } -> [ string ]
|
# { ... } -> [ string ]
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ let
|
|||||||
modules = [
|
modules = [
|
||||||
clanLib.inventory.interface
|
clanLib.inventory.interface
|
||||||
{
|
{
|
||||||
|
_file = "test file";
|
||||||
tags.all = [ ];
|
tags.all = [ ];
|
||||||
tags.nixos = [ ];
|
tags.nixos = [ ];
|
||||||
tags.darwin = [ ];
|
tags.darwin = [ ];
|
||||||
|
|||||||
@@ -56,7 +56,9 @@ let
|
|||||||
{
|
{
|
||||||
constraints.imports = [
|
constraints.imports = [
|
||||||
(lib.modules.importApply ../constraints {
|
(lib.modules.importApply ../constraints {
|
||||||
|
resolvedRoles = { };
|
||||||
moduleName = "{moduleName}";
|
moduleName = "{moduleName}";
|
||||||
|
instanceName = "{instanceName}";
|
||||||
allRoles = [ "{roleName}" ];
|
allRoles = [ "{roleName}" ];
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -18,9 +18,10 @@ let
|
|||||||
|
|
||||||
frontMatterSchema = jsonLib.parseOptions self.clanLib.modules.frontmatterOptions { };
|
frontMatterSchema = jsonLib.parseOptions self.clanLib.modules.frontmatterOptions { };
|
||||||
|
|
||||||
inventorySchema = jsonLib.parseModule (
|
inventorySchema = jsonLib.parseModule ({
|
||||||
import ../build-inventory/interface.nix { inherit (self) clanLib; }
|
imports = [ ../build-inventory/interface.nix ];
|
||||||
);
|
_module.args = { inherit (self) clanLib; };
|
||||||
|
});
|
||||||
|
|
||||||
clanSchema = jsonLib.parseOptions (flakeOptions.clan.type.getSubOptions [ "clan" ]) { };
|
clanSchema = jsonLib.parseOptions (flakeOptions.clan.type.getSubOptions [ "clan" ]) { };
|
||||||
|
|
||||||
|
|||||||
@@ -100,7 +100,11 @@ in
|
|||||||
inventory = lib.mkOption {
|
inventory = lib.mkOption {
|
||||||
type = types.submodule {
|
type = types.submodule {
|
||||||
imports = [
|
imports = [
|
||||||
(lib.modules.importApply ../../inventory/build-inventory/interface.nix { inherit clanLib; })
|
{
|
||||||
|
_module.args = { inherit clanLib; };
|
||||||
|
_file = "clan interface";
|
||||||
|
}
|
||||||
|
../../inventory/build-inventory/interface.nix
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
description = ''
|
description = ''
|
||||||
|
|||||||
Reference in New Issue
Block a user