fix(clanLib): propagate clanLib into module apply

This commit is contained in:
Johannes Kirschbauer
2025-05-21 19:00:46 +02:00
parent 2510b2bb77
commit 8576016b32
10 changed files with 36 additions and 15 deletions

View File

@@ -3,12 +3,13 @@
## Add any logic to ./module.nix ## Add any logic to ./module.nix
{ {
lib, lib,
clanLib,
... ...
}: }:
{ {
flakePartsModule = { flakePartsModule = {
imports = [ imports = [
./interface.nix (lib.modules.importApply ./interface.nix { inherit clanLib; })
./module.nix ./module.nix
]; ];
}; };

View File

@@ -1,9 +1,13 @@
{ pkgs, lib }: {
pkgs,
lib,
clanLib,
}:
let let
eval = lib.evalModules { eval = lib.evalModules {
class = "nixos"; class = "nixos";
modules = [ modules = [
./interface.nix (lib.modules.importApply ./interface.nix { inherit clanLib; })
]; ];
}; };
evalDocs = pkgs.nixosOptionsDoc { evalDocs = pkgs.nixosOptionsDoc {

View File

@@ -19,6 +19,7 @@ in
let let
jsonDocs = import ./eval-docs.nix { jsonDocs = import ./eval-docs.nix {
inherit pkgs lib; inherit pkgs lib;
inherit (self) clanLib;
}; };
in in
{ {

View File

@@ -18,7 +18,7 @@ module:
; ;
}; };
modules = [ modules = [
./interface.nix (lib.modules.importApply ./interface.nix { inherit (clan-core) clanLib; })
module module
{ {
inherit specialArgs; inherit specialArgs;

View File

@@ -1,3 +1,4 @@
{ clanLib }:
{ {
lib, lib,
self, self,
@@ -94,7 +95,11 @@ in
}; };
inventory = lib.mkOption { inventory = lib.mkOption {
type = types.submodule { imports = [ ../inventory/build-inventory/interface.nix ]; }; type = types.submodule {
imports = [
(lib.modules.importApply ../inventory/build-inventory/interface.nix { inherit clanLib; })
];
};
description = '' description = ''
The `Inventory` submodule. The `Inventory` submodule.

View File

@@ -403,7 +403,7 @@ in
}; };
settings = lib.mkOption { settings = lib.mkOption {
default = { }; default = { };
type = types.uniqueDeferredSerializableModule; type = clanLib.types.uniqueDeferredSerializableModule;
}; };
}; };
} }

View File

@@ -5,7 +5,7 @@ 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 = ./build-inventory/interface.nix; interface = lib.modules.importApply ./build-inventory/interface.nix { inherit clanLib; };
# Returns the list of machine names # Returns the list of machine names
# { ... } -> [ string ] # { ... } -> [ string ]
resolveTags = resolveTags =

View File

@@ -17,7 +17,9 @@ let
frontMatterSchema = jsonLib.parseOptions self.clanLib.modules.frontmatterOptions { }; frontMatterSchema = jsonLib.parseOptions self.clanLib.modules.frontmatterOptions { };
inventorySchema = jsonLib.parseModule (import ../build-inventory/interface.nix); inventorySchema = jsonLib.parseModule (
import ../build-inventory/interface.nix { inherit (self) clanLib; }
);
renderSchema = pkgs.writers.writePython3Bin "render-schema" { renderSchema = pkgs.writers.writePython3Bin "render-schema" {
flakeIgnore = [ flakeIgnore = [

View File

@@ -4,7 +4,12 @@
self: self:
let let
checkDef = loc: def: if def.value ? imports then throw "uniqueDeferredSerializableModule doesn't allow nested imports" else def; checkDef =
_loc: def:
if def.value ? imports then
throw "uniqueDeferredSerializableModule doesn't allow nested imports"
else
def;
in in
# Essentially the "raw" type, but with a custom name and check # Essentially the "raw" type, but with a custom name and check
lib.mkOptionType { lib.mkOptionType {
@@ -18,8 +23,9 @@
merge = loc: defs: { merge = loc: defs: {
imports = map ( imports = map (
def: def:
lib.seq (checkDef loc def) lib.seq (checkDef loc def) lib.setDefaultModuleLocation
lib.setDefaultModuleLocation "${def.file}, via option ${lib.showOption loc}" def.value "${def.file}, via option ${lib.showOption loc}"
def.value
) defs; ) defs;
}; };
}; };

View File

@@ -43,7 +43,7 @@ in
let let
eval = evalSettingsModule { eval = evalSettingsModule {
foo = { foo = {
imports = []; imports = [ ];
}; };
}; };
in in
@@ -53,15 +53,17 @@ in
expectedError = { expectedError = {
type = "ThrownError"; type = "ThrownError";
message = "*nested imports"; message = "*nested imports";
}; };
}; };
test_no_function_modules = test_no_function_modules =
let let
eval = evalSettingsModule { eval = evalSettingsModule {
foo = {...}: { foo =
{ ... }:
{
}; };
}; };
in in
{ {