inventory/interface: reduce apply arguments chain by adding it to _module.args

This commit is contained in:
Johannes Kirschbauer
2025-06-25 13:39:41 +02:00
parent ac7c51d2b3
commit 0bb621f0f7
7 changed files with 35 additions and 22 deletions

View File

@@ -122,8 +122,8 @@
mkOption {
type = types.submodule {
imports = [
{ _module.args = { inherit clanLib; }; }
(import ../../../lib/inventory/build-inventory/roles-interface.nix {
inherit clanLib;
nestedSettingsOption = mkOption {
type = types.raw;
description = ''
@@ -148,10 +148,9 @@
mkScope = name: modules: {
inherit name;
modules = [
(import ../../../lib/inventory/build-inventory/interface.nix {
inherit clanLib;
noInstanceOptions = true;
})
{ _module.args = { inherit clanLib; }; }
{ noInstanceOptions = true; }
../../../lib/inventory/build-inventory/interface.nix
] ++ mapAttrsToList fakeInstanceOptions modules;
urlPrefix = "https://github.com/nix-community/dream2nix/blob/main/";
};

View File

@@ -1,10 +1,6 @@
{
clanLib,
# workaround for docs rendering to include fake instance options
noInstanceOptions ? false,
}:
{
lib,
clanLib,
config,
options,
...
@@ -101,6 +97,7 @@ in
./assertions.nix
];
options = {
# Internal things
_inventoryFile = lib.mkOption {
type = types.path;
readOnly = true;
@@ -112,6 +109,12 @@ in
visible = false;
default = { };
};
noInstanceOptions = lib.mkOption {
type = types.bool;
internal = true;
visible = false;
default = false;
};
options = lib.mkOption {
internal = true;
@@ -119,6 +122,8 @@ in
type = types.raw;
default = options;
};
# ---------------------------
modules = lib.mkOption {
# Don't define the type yet
# We manually transform the value with types.deferredModule.merge later to keep them serializable
@@ -375,7 +380,7 @@ in
};
instances =
if noInstanceOptions then
if config.noInstanceOptions then
{ }
else
lib.mkOption {
@@ -414,7 +419,14 @@ in
default = { };
type = types.attrsOf (
types.submodule {
imports = [ (import ./roles-interface.nix { inherit clanLib; }) ];
imports = [
{
_module.args = {
inherit clanLib;
};
}
(import ./roles-interface.nix { })
];
}
);
};

View File

@@ -1,9 +1,8 @@
{
clanLib,
settingsOption ? null,
nestedSettingsOption ? null,
}:
{ lib, ... }:
{ lib, clanLib, ... }:
let
inherit (lib)
types

View File

@@ -7,11 +7,9 @@ in
inherit (import ./build-inventory { inherit lib clanLib; }) buildInventory;
interface = {
imports = [
(import ./build-inventory/interface.nix { inherit clanLib; })
./build-inventory/interface.nix
];
_module.args = {
inherit clanLib;
};
_module.args = { inherit clanLib; };
};
# Returns the list of machine names
# { ... } -> [ string ]

View File

@@ -15,6 +15,9 @@ let
modules = [
clanLib.inventory.interface
{
_module.args = {
inherit clanLib;
};
tags.all = [ ];
tags.nixos = [ ];
tags.darwin = [ ];

View File

@@ -18,9 +18,10 @@ let
frontMatterSchema = jsonLib.parseOptions self.clanLib.modules.frontmatterOptions { };
inventorySchema = jsonLib.parseModule (
import ../build-inventory/interface.nix { inherit (self) clanLib; }
);
inventorySchema = jsonLib.parseModule ({
imports = [ ../build-inventory/interface.nix ];
_module.args = { inherit (self) clanLib; };
});
clanSchema = jsonLib.parseOptions (flakeOptions.clan.type.getSubOptions [ "clan" ]) { };

View File

@@ -100,7 +100,8 @@ in
inventory = lib.mkOption {
type = types.submodule {
imports = [
(lib.modules.importApply ../../inventory/build-inventory/interface.nix { inherit clanLib; })
{ _module.args = { inherit clanLib; }; }
../../inventory/build-inventory/interface.nix
];
};
description = ''