lib/clan: add checks
This commit is contained in:
@@ -39,23 +39,32 @@ in
|
|||||||
};
|
};
|
||||||
modules = [
|
modules = [
|
||||||
clan-core.modules.clan.default
|
clan-core.modules.clan.default
|
||||||
|
{
|
||||||
|
checks.minNixpkgsVersion = {
|
||||||
|
assertion = lib.versionAtLeast nixpkgs.lib.version "25.11";
|
||||||
|
message = ''
|
||||||
|
Nixpkgs version: ${nixpkgs.lib.version} is incompatible with clan-core. (>= 25.11 is recommended)
|
||||||
|
---
|
||||||
|
Your version of 'nixpkgs' seems too old for clan-core.
|
||||||
|
Please read: https://docs.clan.lol/guides/nixpkgs-flake-input
|
||||||
|
|
||||||
|
You can ignore this check by setting:
|
||||||
|
clan.checks.minNixpkgsVersion.ignore = true;
|
||||||
|
---
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
apply =
|
apply =
|
||||||
config:
|
config:
|
||||||
# TOOD:
|
lib.deepSeq (lib.mapAttrs (
|
||||||
# - allow to disable version check?
|
id: check:
|
||||||
# - self-incrementing version?
|
if check.ignore || check.assertion then
|
||||||
if !lib.versionAtLeast nixpkgs.lib.version "25.11" then
|
null
|
||||||
throw ''
|
else
|
||||||
Nixpkgs version: ${nixpkgs.lib.version} is incompatible with clan-core. (>= 25.11 is required)
|
throw "clan.checks.${id} failed with message\n${check.message}"
|
||||||
---
|
) config.checks) config;
|
||||||
Your version of 'nixpkgs' seems too old for clan-core.
|
|
||||||
Please read: https://docs.clan.lol/guides/nixpkgs-flake-input
|
|
||||||
---
|
|
||||||
''
|
|
||||||
else
|
|
||||||
config;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
# Mapped flake toplevel outputs
|
# Mapped flake toplevel outputs
|
||||||
|
|||||||
@@ -9,6 +9,36 @@
|
|||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
types = lib.types;
|
types = lib.types;
|
||||||
|
|
||||||
|
checkType = types.attrsOf (
|
||||||
|
types.submodule {
|
||||||
|
# Skip entire evaluation of this check
|
||||||
|
options.ignore = lib.mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = "Ignores this check entirely";
|
||||||
|
};
|
||||||
|
|
||||||
|
# Can only be defined once
|
||||||
|
options.assertion = lib.mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
readOnly = true;
|
||||||
|
description = ''
|
||||||
|
The assertion that must hold true.
|
||||||
|
|
||||||
|
If false, the message is shown.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
# Message shown when the assertion is false
|
||||||
|
options.message = lib.mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = "Message shown when the assertion is false";
|
||||||
|
};
|
||||||
|
|
||||||
|
# TODO: add severity levels?
|
||||||
|
# Fail, Warn, Log
|
||||||
|
}
|
||||||
|
);
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
@@ -18,6 +48,17 @@ in
|
|||||||
visible = false;
|
visible = false;
|
||||||
default = [ ];
|
default = [ ];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# id :: { assertion, message }
|
||||||
|
checks = lib.mkOption {
|
||||||
|
type = checkType;
|
||||||
|
default = { };
|
||||||
|
description = ''
|
||||||
|
Assertions that must hold true when evaluating the clan.
|
||||||
|
When the assertion fails, the message is shown and the evaluation is aborted.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
self = lib.mkOption {
|
self = lib.mkOption {
|
||||||
type = types.raw;
|
type = types.raw;
|
||||||
default = self;
|
default = self;
|
||||||
|
|||||||
Reference in New Issue
Block a user