mirror of
https://github.com/SebastianStork/nixos-config.git
synced 2026-01-21 16:21:34 +01:00
Add global domains list
This commit is contained in:
parent
7a9796e02c
commit
f3c3d3268c
2 changed files with 68 additions and 55 deletions
|
|
@ -6,29 +6,6 @@
|
|||
}:
|
||||
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 = {
|
||||
|
|
@ -37,17 +14,51 @@ in
|
|||
default = [ ];
|
||||
internal = true;
|
||||
};
|
||||
globalList = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.nonEmptyStr;
|
||||
default =
|
||||
self.nixosConfigurations
|
||||
|> lib.mapAttrsToList (_: value: value.config.meta.domains.list)
|
||||
|> lib.concatLists;
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
};
|
||||
assertUnique = lib.mkEnableOption "" // {
|
||||
default = true;
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.assertUnique {
|
||||
assertions = [
|
||||
{
|
||||
assertion = duplicatedDomains == { };
|
||||
message = errorMessage;
|
||||
}
|
||||
];
|
||||
assertions =
|
||||
let
|
||||
duplicateDomains =
|
||||
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 =
|
||||
duplicateDomains
|
||||
|> lib.mapAttrsToList (
|
||||
domain: entries:
|
||||
"Duplicate domain \"${domain}\" found in:\n"
|
||||
+ lib.concatMapStrings (entry: " - ${entry.file}\n") entries
|
||||
)
|
||||
|> lib.concatStrings;
|
||||
in
|
||||
[
|
||||
{
|
||||
assertion = duplicateDomains == { };
|
||||
message = errorMessage;
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,26 +6,6 @@
|
|||
}:
|
||||
let
|
||||
cfg = config.meta.ports;
|
||||
|
||||
duplicatedPorts =
|
||||
options.meta.ports.list.definitionsWithLocations
|
||||
|> lib.concatMap (
|
||||
entry:
|
||||
map (port: {
|
||||
file = entry.file;
|
||||
inherit port;
|
||||
}) entry.value
|
||||
)
|
||||
|> lib.groupBy (entry: toString entry.port)
|
||||
|> lib.filterAttrs (port: entries: lib.length entries > 1);
|
||||
|
||||
errorMessage =
|
||||
duplicatedPorts
|
||||
|> lib.mapAttrsToList (
|
||||
port: entries:
|
||||
"Duplicate port ${port} found in:\n" + lib.concatMapStrings (entry: " - ${entry.file}\n") entries
|
||||
)
|
||||
|> lib.concatStrings;
|
||||
in
|
||||
{
|
||||
options.meta.ports = {
|
||||
|
|
@ -40,11 +20,33 @@ in
|
|||
};
|
||||
|
||||
config = lib.mkIf cfg.assertUnique {
|
||||
assertions = [
|
||||
{
|
||||
assertion = duplicatedPorts == { };
|
||||
message = errorMessage;
|
||||
}
|
||||
];
|
||||
assertions =
|
||||
let
|
||||
duplicatePorts =
|
||||
options.meta.ports.list.definitionsWithLocations
|
||||
|> lib.concatMap (
|
||||
entry:
|
||||
map (port: {
|
||||
inherit (entry) file;
|
||||
inherit port;
|
||||
}) entry.value
|
||||
)
|
||||
|> lib.groupBy (entry: toString entry.port)
|
||||
|> lib.filterAttrs (port: entries: lib.length entries > 1);
|
||||
|
||||
errorMessage =
|
||||
duplicatePorts
|
||||
|> lib.mapAttrsToList (
|
||||
port: entries:
|
||||
"Duplicate port ${port} found in:\n" + lib.concatMapStrings (entry: " - ${entry.file}\n") entries
|
||||
)
|
||||
|> lib.concatStrings;
|
||||
in
|
||||
[
|
||||
{
|
||||
assertion = duplicatePorts == { };
|
||||
message = errorMessage;
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue