inventory: make resolve module a clanLib function
Unclutter inventory logic
This commit is contained in:
@@ -32,9 +32,6 @@ in
|
||||
inherit lib;
|
||||
clanLib = self.clanLib;
|
||||
};
|
||||
legacyPackages.eval-tests-resolve-module = import ./test-resolve-module.nix {
|
||||
inherit lib;
|
||||
};
|
||||
|
||||
checks = {
|
||||
eval-lib-distributedServices = pkgs.runCommand "tests" { nativeBuildInputs = [ pkgs.nix-unit ]; } ''
|
||||
@@ -47,16 +44,6 @@ in
|
||||
|
||||
touch $out
|
||||
'';
|
||||
eval-tests-resolve-module = pkgs.runCommand "tests" { nativeBuildInputs = [ pkgs.nix-unit ]; } ''
|
||||
export HOME="$(realpath .)"
|
||||
nix-unit --eval-store "$HOME" \
|
||||
--extra-experimental-features flakes \
|
||||
--show-trace \
|
||||
${inputOverrides} \
|
||||
--flake ${inventoryTestsSrc}#legacyPackages.${system}.eval-tests-resolve-module
|
||||
|
||||
touch $out
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,9 +14,6 @@
|
||||
clanLib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
resolveModule = import ./resolveModule.nix { inherit lib; };
|
||||
in
|
||||
{
|
||||
mapInstances =
|
||||
{
|
||||
@@ -36,7 +33,7 @@ in
|
||||
importedModuleWithInstances = lib.mapAttrs (
|
||||
instanceName: instance:
|
||||
let
|
||||
resolvedModule = resolveModule {
|
||||
resolvedModule = clanLib.resolveModule {
|
||||
moduleSpec = instance.module;
|
||||
inherit flakeInputs clanCoreModules;
|
||||
};
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
{ lib }:
|
||||
{
|
||||
moduleSpec,
|
||||
flakeInputs,
|
||||
clanCoreModules,
|
||||
}:
|
||||
let
|
||||
inputError = throw ''
|
||||
Flake doesn't provide input with name '${moduleSpec.input}'
|
||||
|
||||
Choose one of the following inputs:
|
||||
- ${
|
||||
builtins.concatStringsSep "\n- " (
|
||||
lib.attrNames (lib.filterAttrs (_name: input: input ? clan) flakeInputs)
|
||||
)
|
||||
}
|
||||
|
||||
To import a local module from 'clan.modules' remove the 'input' attribute from the module definition
|
||||
Remove the following line from the module definition:
|
||||
|
||||
...
|
||||
- module.input = "${moduleSpec.input}"
|
||||
|
||||
'';
|
||||
resolvedModuleSet =
|
||||
# If the module.name is self then take the modules defined in the flake
|
||||
# Otherwise its an external input which provides the modules via 'clan.modules' attribute
|
||||
let
|
||||
input =
|
||||
if moduleSpec.input == null then
|
||||
{ clan.modules = clanCoreModules; }
|
||||
else
|
||||
flakeInputs.${moduleSpec.input} or inputError;
|
||||
in
|
||||
input.clan.modules
|
||||
or (throw "flake input '${moduleSpec.input}' doesn't export any clan services via the `clan.modules` output attribute");
|
||||
|
||||
resolvedModule =
|
||||
resolvedModuleSet.${moduleSpec.name} or (throw ''
|
||||
${
|
||||
lib.optionalString (
|
||||
moduleSpec.input != null
|
||||
) "flake input '${moduleSpec.input}' doesn't provide clan-module with name '${moduleSpec.name}'."
|
||||
}${
|
||||
lib.optionalString (
|
||||
moduleSpec.input == null
|
||||
) "clan-core doesn't provide clan-module with name '${moduleSpec.name}'."
|
||||
}
|
||||
|
||||
Set `module.input = "self"` if the module is defined in your own flake.
|
||||
Set `module.input = "<flake-input>" if the module is defined by a flake input called `<flake-input>`.
|
||||
Unset `module.input` (or set module.input = null) - to use the clan-core module '${moduleSpec.name}'
|
||||
'');
|
||||
in
|
||||
resolvedModule
|
||||
@@ -1,69 +0,0 @@
|
||||
# Run: nix-unit ./test-resolve-module.nix
|
||||
{
|
||||
lib ? import <nixpkgs/lib>,
|
||||
}:
|
||||
let
|
||||
resolveModule = import ./resolveModule.nix { inherit lib; };
|
||||
|
||||
fromSpec =
|
||||
moduleSpec:
|
||||
resolveModule {
|
||||
inherit moduleSpec;
|
||||
flakeInputs = {
|
||||
self.clan.modules = {
|
||||
foo = {
|
||||
name = "self/foo";
|
||||
};
|
||||
};
|
||||
};
|
||||
clanCoreModules = {
|
||||
foo = {
|
||||
name = "clan/foo";
|
||||
};
|
||||
bar = {
|
||||
name = "clan/bar";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
in
|
||||
{
|
||||
test_default_clan_core = {
|
||||
expr = fromSpec {
|
||||
name = "foo";
|
||||
input = null;
|
||||
};
|
||||
expected = {
|
||||
name = "clan/foo";
|
||||
};
|
||||
};
|
||||
test_self_module = {
|
||||
expr = fromSpec {
|
||||
name = "foo";
|
||||
input = "self";
|
||||
};
|
||||
expected = {
|
||||
name = "self/foo";
|
||||
};
|
||||
};
|
||||
test_missing_self_module = {
|
||||
expr = fromSpec {
|
||||
name = "bar";
|
||||
input = "self";
|
||||
};
|
||||
expectedError = {
|
||||
type = "ThrownError";
|
||||
msg = "flake input 'self' doesn't provide clan-module with name 'bar'";
|
||||
};
|
||||
};
|
||||
test_missing_core_module = {
|
||||
expr = fromSpec {
|
||||
name = "nana";
|
||||
input = null;
|
||||
};
|
||||
expectedError = {
|
||||
type = "ThrownError";
|
||||
msg = "clan-core doesn't provide clan-module with name 'nana'";
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user