diff --git a/docs/nix/options/flake-module.nix b/docs/nix/options/flake-module.nix index b21e71bd1..ed70300d9 100644 --- a/docs/nix/options/flake-module.nix +++ b/docs/nix/options/flake-module.nix @@ -121,9 +121,10 @@ roleName: roleSettingsModule: mkOption { type = types.submodule { + _file = "docs flake-module"; imports = [ + { _module.args = { inherit clanLib; }; } (import ../../../lib/inventory/build-inventory/roles-interface.nix { - inherit clanLib; nestedSettingsOption = mkOption { type = types.raw; description = '' @@ -148,10 +149,12 @@ mkScope = name: modules: { inherit name; modules = [ - (import ../../../lib/inventory/build-inventory/interface.nix { - inherit clanLib; - noInstanceOptions = true; - }) + { + _module.args = { inherit clanLib; }; + _file = "docs mkScope"; + } + { noInstanceOptions = true; } + ../../../lib/inventory/build-inventory/interface.nix ] ++ mapAttrsToList fakeInstanceOptions modules; urlPrefix = "https://github.com/nix-community/dream2nix/blob/main/"; }; diff --git a/lib/inventory/build-inventory/builder/default.nix b/lib/inventory/build-inventory/builder/default.nix index 01e7d6b6b..c25ea7057 100644 --- a/lib/inventory/build-inventory/builder/default.nix +++ b/lib/inventory/build-inventory/builder/default.nix @@ -170,6 +170,7 @@ in getRoleFile = role: builtins.seq role inventory.modules.${serviceName} + "/roles/${role}.nix"; in { + _file = "inventory/builder.nix"; _module.args = { inherit resolveTags diff --git a/lib/inventory/build-inventory/interface.nix b/lib/inventory/build-inventory/interface.nix index b02411b59..6807cdca6 100644 --- a/lib/inventory/build-inventory/interface.nix +++ b/lib/inventory/build-inventory/interface.nix @@ -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,15 @@ in default = { }; type = types.attrsOf ( types.submodule { - imports = [ (import ./roles-interface.nix { inherit clanLib; }) ]; + imports = [ + { + _file = "inventory/interface"; + _module.args = { + inherit clanLib; + }; + } + (import ./roles-interface.nix { }) + ]; } ); }; diff --git a/lib/inventory/build-inventory/roles-interface.nix b/lib/inventory/build-inventory/roles-interface.nix index 61481f15e..da66774d9 100644 --- a/lib/inventory/build-inventory/roles-interface.nix +++ b/lib/inventory/build-inventory/roles-interface.nix @@ -1,9 +1,8 @@ { - clanLib, settingsOption ? null, nestedSettingsOption ? null, }: -{ lib, ... }: +{ lib, clanLib, ... }: let inherit (lib) types diff --git a/lib/inventory/default.nix b/lib/inventory/default.nix index 129782dd9..894116451 100644 --- a/lib/inventory/default.nix +++ b/lib/inventory/default.nix @@ -6,12 +6,11 @@ in inherit (services) evalClanService mapInstances resolveModule; inherit (import ./build-inventory { inherit lib clanLib; }) buildInventory; interface = { + _file = "inventory/default.nix"; 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 ] diff --git a/lib/inventory/distributed-service/tests/default.nix b/lib/inventory/distributed-service/tests/default.nix index b4fb4221b..cf4fcb39b 100644 --- a/lib/inventory/distributed-service/tests/default.nix +++ b/lib/inventory/distributed-service/tests/default.nix @@ -15,6 +15,7 @@ let modules = [ clanLib.inventory.interface { + _file = "test file"; tags.all = [ ]; tags.nixos = [ ]; tags.darwin = [ ]; diff --git a/lib/inventory/frontmatter/default.nix b/lib/inventory/frontmatter/default.nix index 83fda98e3..383779b99 100644 --- a/lib/inventory/frontmatter/default.nix +++ b/lib/inventory/frontmatter/default.nix @@ -56,7 +56,9 @@ let { constraints.imports = [ (lib.modules.importApply ../constraints { + resolvedRoles = { }; moduleName = "{moduleName}"; + instanceName = "{instanceName}"; allRoles = [ "{roleName}" ]; }) ]; diff --git a/lib/inventory/schemas/default.nix b/lib/inventory/schemas/default.nix index 65d16fe88..9c725db3a 100644 --- a/lib/inventory/schemas/default.nix +++ b/lib/inventory/schemas/default.nix @@ -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" ]) { }; diff --git a/lib/modules/clan/interface.nix b/lib/modules/clan/interface.nix index bf4599ef3..d96841ee2 100644 --- a/lib/modules/clan/interface.nix +++ b/lib/modules/clan/interface.nix @@ -100,7 +100,11 @@ in inventory = lib.mkOption { type = types.submodule { imports = [ - (lib.modules.importApply ../../inventory/build-inventory/interface.nix { inherit clanLib; }) + { + _module.args = { inherit clanLib; }; + _file = "clan interface"; + } + ../../inventory/build-inventory/interface.nix ]; }; description = ''