mirror of
https://github.com/SebastianStork/nixos-config.git
synced 2026-01-21 14:01:34 +01:00
Add uniqueness check for domains
This commit is contained in:
parent
232c9aa946
commit
f160a9be33
3 changed files with 59 additions and 2 deletions
53
modules/system/meta/domains.nix
Normal file
53
modules/system/meta/domains.nix
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
{
|
||||
config,
|
||||
self,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
cfg = config.meta.domains;
|
||||
|
||||
duplicatedDomains =
|
||||
self.nixosConfigurations
|
||||
|> lib.mapAttrsToList (_: value: value.options.meta.domains.list.definitionsWithLocations)
|
||||
|> lib.concatLists
|
||||
|> lib.concatMap (
|
||||
entry:
|
||||
map (domain: {
|
||||
file = entry.file;
|
||||
inherit domain;
|
||||
}) entry.value
|
||||
)
|
||||
|> lib.groupBy (entry: toString entry.domain)
|
||||
|> lib.filterAttrs (domain: entries: lib.length entries > 1);
|
||||
|
||||
errorMessage =
|
||||
duplicatedDomains
|
||||
|> lib.mapAttrsToList (
|
||||
domain: entries:
|
||||
"Duplicate domain \"${domain}\" found in:\n"
|
||||
+ lib.concatMapStrings (entry: " - ${entry.file}\n") entries
|
||||
)
|
||||
|> lib.concatStrings;
|
||||
in
|
||||
{
|
||||
options.meta.domains = {
|
||||
list = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.nonEmptyStr;
|
||||
default = [ ];
|
||||
internal = true;
|
||||
};
|
||||
assertUnique = lib.mkEnableOption "" // {
|
||||
default = true;
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.assertUnique {
|
||||
assertions = [
|
||||
{
|
||||
assertion = duplicatedDomains == { };
|
||||
message = errorMessage;
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue