inventory: make resolve module a clanLib function
Unclutter inventory logic
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
# TODO: Get rid of self here.
|
# TODO: Get rid of self here.
|
||||||
# DONT add any new functions that depend on self here.
|
# DONT add any new functions that depend on self here.
|
||||||
# If a lib function depends on a piece in clan-core add that piece to the function arguments
|
# If a lib function depends on a piece in clan-core add that piece to the function arguments
|
||||||
self,
|
self ? throw "'self' should not be used in lib/default.nix, dont depend on it. It will be removed in short notice.",
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
# Produces the
|
# Produces the
|
||||||
@@ -48,5 +48,8 @@ lib.fix (
|
|||||||
|
|
||||||
# flakes
|
# flakes
|
||||||
flakes = clanLib.callLib ./flakes.nix { };
|
flakes = clanLib.callLib ./flakes.nix { };
|
||||||
|
|
||||||
|
# TODO: Flatten our lib functions like this:
|
||||||
|
resolveModule = clanLib.callLib ./resolve-module { };
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -4,6 +4,9 @@
|
|||||||
self,
|
self,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
|
let
|
||||||
|
inputOverrides = self.clanLib.flake-inputs.getOverrides inputs;
|
||||||
|
in
|
||||||
rec {
|
rec {
|
||||||
# TODO: automatically generate this from the directory conventions
|
# TODO: automatically generate this from the directory conventions
|
||||||
imports = [
|
imports = [
|
||||||
@@ -19,4 +22,47 @@ rec {
|
|||||||
};
|
};
|
||||||
# TODO: remove this legacy alias
|
# TODO: remove this legacy alias
|
||||||
flake.lib = flake.clanLib;
|
flake.lib = flake.clanLib;
|
||||||
|
|
||||||
|
perSystem =
|
||||||
|
{
|
||||||
|
pkgs,
|
||||||
|
lib,
|
||||||
|
system,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
# Common filtered source for module tests
|
||||||
|
inventoryTestsSrc = lib.fileset.toSource {
|
||||||
|
root = ../.;
|
||||||
|
fileset = lib.fileset.unions [
|
||||||
|
../flake.nix
|
||||||
|
../flake.lock
|
||||||
|
../lib
|
||||||
|
(lib.fileset.fileFilter (file: file.name == "flake-module.nix") ../.)
|
||||||
|
../flakeModules
|
||||||
|
# ../../nixosModules/clanCore
|
||||||
|
# ../../machines
|
||||||
|
# ../../inventory.json
|
||||||
|
];
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
legacyPackages.eval-tests-resolve-module = import ./resolve-module/test.nix {
|
||||||
|
inherit lib;
|
||||||
|
};
|
||||||
|
|
||||||
|
checks = {
|
||||||
|
eval-lib-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
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,9 +32,6 @@ in
|
|||||||
inherit lib;
|
inherit lib;
|
||||||
clanLib = self.clanLib;
|
clanLib = self.clanLib;
|
||||||
};
|
};
|
||||||
legacyPackages.eval-tests-resolve-module = import ./test-resolve-module.nix {
|
|
||||||
inherit lib;
|
|
||||||
};
|
|
||||||
|
|
||||||
checks = {
|
checks = {
|
||||||
eval-lib-distributedServices = pkgs.runCommand "tests" { nativeBuildInputs = [ pkgs.nix-unit ]; } ''
|
eval-lib-distributedServices = pkgs.runCommand "tests" { nativeBuildInputs = [ pkgs.nix-unit ]; } ''
|
||||||
@@ -47,16 +44,6 @@ in
|
|||||||
|
|
||||||
touch $out
|
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,
|
clanLib,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
|
||||||
resolveModule = import ./resolveModule.nix { inherit lib; };
|
|
||||||
in
|
|
||||||
{
|
{
|
||||||
mapInstances =
|
mapInstances =
|
||||||
{
|
{
|
||||||
@@ -36,7 +33,7 @@ in
|
|||||||
importedModuleWithInstances = lib.mapAttrs (
|
importedModuleWithInstances = lib.mapAttrs (
|
||||||
instanceName: instance:
|
instanceName: instance:
|
||||||
let
|
let
|
||||||
resolvedModule = resolveModule {
|
resolvedModule = clanLib.resolveModule {
|
||||||
moduleSpec = instance.module;
|
moduleSpec = instance.module;
|
||||||
inherit flakeInputs clanCoreModules;
|
inherit flakeInputs clanCoreModules;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,12 @@
|
|||||||
{ lib }:
|
{ lib, ... }:
|
||||||
|
/**
|
||||||
|
Resolve a module from either the clan-core modules or from a flake input.
|
||||||
|
|
||||||
|
The logic is as follows:
|
||||||
|
- If the moduleSpec.input is null then the module is looked up in the clanCore
|
||||||
|
- If the moduleSpec.input is set to a string then the module is looked up in the
|
||||||
|
flake input with that name.
|
||||||
|
*/
|
||||||
{
|
{
|
||||||
moduleSpec,
|
moduleSpec,
|
||||||
flakeInputs,
|
flakeInputs,
|
||||||
@@ -9,13 +17,9 @@ let
|
|||||||
Flake doesn't provide input with name '${moduleSpec.input}'
|
Flake doesn't provide input with name '${moduleSpec.input}'
|
||||||
|
|
||||||
Choose one of the following inputs:
|
Choose one of the following inputs:
|
||||||
- ${
|
- ${builtins.concatStringsSep "\n- " (lib.attrNames (flakeInputs))}
|
||||||
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
|
To import any official module from '<clan-core>' remove the 'input' attribute from the module definition
|
||||||
Remove the following line from the module definition:
|
Remove the following line from the module definition:
|
||||||
|
|
||||||
...
|
...
|
||||||
@@ -47,9 +51,10 @@ let
|
|||||||
) "clan-core doesn't provide clan-module with name '${moduleSpec.name}'."
|
) "clan-core doesn't provide clan-module with name '${moduleSpec.name}'."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Remove `module.input` (or set module.input = null) - to use a <clan-core> module'
|
||||||
|
|
||||||
Set `module.input = "self"` if the module is defined in your own flake.
|
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>`.
|
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
|
in
|
||||||
resolvedModule
|
resolvedModule
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
# Run: nix-unit ./test-resolve-module.nix
|
# Run: nix-unit ./test-resolve-module.nix
|
||||||
{
|
{
|
||||||
lib ? import <nixpkgs/lib>,
|
lib ? import <nixpkgs/lib>,
|
||||||
|
clanLib ? import ../default.nix { inherit lib; },
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
resolveModule = import ./resolveModule.nix { inherit lib; };
|
resolveModule = clanLib.resolveModule;
|
||||||
|
|
||||||
fromSpec =
|
fromSpec =
|
||||||
moduleSpec:
|
moduleSpec:
|
||||||
Reference in New Issue
Block a user