Merge pull request 'clan/checks: move into lib function; add tests' (#5683) from role-settings into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/5683
This commit is contained in:
@@ -56,15 +56,8 @@ in
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
apply =
|
# Important: !This logic needs to be kept in sync with lib.clan function!
|
||||||
config:
|
apply = config: clan-core.lib.checkConfig config.checks config;
|
||||||
lib.deepSeq (lib.mapAttrs (
|
|
||||||
id: check:
|
|
||||||
if check.ignore || check.assertion then
|
|
||||||
null
|
|
||||||
else
|
|
||||||
throw "clan.checks.${id} failed with message\n${check.message}"
|
|
||||||
) config.checks) config;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
# Mapped flake toplevel outputs
|
# Mapped flake toplevel outputs
|
||||||
|
|||||||
19
lib/clan/checkConfig.nix
Normal file
19
lib/clan/checkConfig.nix
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{ lib, ... }:
|
||||||
|
/**
|
||||||
|
Function to assert clan configuration checks.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
- 'checks' attribute of clan configuration
|
||||||
|
- Any: the returned configuration (can be anything, is just passed through)
|
||||||
|
*/
|
||||||
|
checks:
|
||||||
|
lib.deepSeq (
|
||||||
|
lib.mapAttrs (
|
||||||
|
id: check:
|
||||||
|
if check.ignore || check.assertion then
|
||||||
|
null
|
||||||
|
else
|
||||||
|
throw "clan.checks.${id} failed with message\n${check.message}"
|
||||||
|
) checks
|
||||||
|
)
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
let
|
let
|
||||||
nixpkgs = self.inputs.nixpkgs or clan-core.inputs.nixpkgs;
|
nixpkgs = self.inputs.nixpkgs or clan-core.inputs.nixpkgs;
|
||||||
nix-darwin = self.inputs.nix-darwin or clan-core.inputs.nix-darwin;
|
nix-darwin = self.inputs.nix-darwin or clan-core.inputs.nix-darwin;
|
||||||
in
|
configuration = (
|
||||||
lib.evalModules {
|
lib.evalModules {
|
||||||
class = "clan";
|
class = "clan";
|
||||||
specialArgs = {
|
specialArgs = {
|
||||||
@@ -50,3 +50,6 @@ lib.evalModules {
|
|||||||
m
|
m
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
in
|
||||||
|
clan-core.clanLib.checkConfig configuration.config.checks configuration
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ lib.fix (
|
|||||||
*/
|
*/
|
||||||
callLib = file: args: import file ({ inherit lib clanLib; } // args);
|
callLib = file: args: import file ({ inherit lib clanLib; } // args);
|
||||||
|
|
||||||
|
checkConfig = clanLib.callLib ./clan/checkConfig.nix { };
|
||||||
|
|
||||||
evalService = clanLib.callLib ./evalService.nix { };
|
evalService = clanLib.callLib ./evalService.nix { };
|
||||||
# ------------------------------------
|
# ------------------------------------
|
||||||
# ClanLib functions
|
# ClanLib functions
|
||||||
|
|||||||
@@ -212,6 +212,36 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
test_clan_check_simple_fail =
|
||||||
|
let
|
||||||
|
eval = clan {
|
||||||
|
checks.constFail = {
|
||||||
|
assertion = false;
|
||||||
|
message = "This is a constant failure";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
result = eval;
|
||||||
|
expr = eval.config;
|
||||||
|
expectedError.type = "ThrownError";
|
||||||
|
expectedError.msg = "This is a constant failure";
|
||||||
|
};
|
||||||
|
test_clan_check_simple_pass =
|
||||||
|
let
|
||||||
|
eval = clan {
|
||||||
|
checks.constFail = {
|
||||||
|
assertion = true;
|
||||||
|
message = "This is a constant success";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
result = eval;
|
||||||
|
expr = lib.seq eval.config 42;
|
||||||
|
expected = 42;
|
||||||
|
};
|
||||||
|
|
||||||
test_get_var_machine =
|
test_get_var_machine =
|
||||||
let
|
let
|
||||||
varsLib = import ./vars.nix { };
|
varsLib = import ./vars.nix { };
|
||||||
|
|||||||
@@ -1,3 +1,14 @@
|
|||||||
|
/**
|
||||||
|
Root 'clan' Module
|
||||||
|
|
||||||
|
Defines lib.clan and flake-parts.clan options
|
||||||
|
and all common logic for the 'clan' module.
|
||||||
|
|
||||||
|
- has Class _class = "clan"
|
||||||
|
|
||||||
|
- _module.args.clan-core: reference to clan-core flake
|
||||||
|
- _module.args.clanLib: reference to lib.clan function
|
||||||
|
*/
|
||||||
{ clan-core }:
|
{ clan-core }:
|
||||||
{
|
{
|
||||||
_class = "clan";
|
_class = "clan";
|
||||||
|
|||||||
Reference in New Issue
Block a user