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,8 +6,32 @@
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
cfg = config.meta.domains;
|
cfg = config.meta.domains;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.meta.domains = {
|
||||||
|
list = lib.mkOption {
|
||||||
|
type = lib.types.listOf lib.types.nonEmptyStr;
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
duplicatedDomains =
|
config = lib.mkIf cfg.assertUnique {
|
||||||
|
assertions =
|
||||||
|
let
|
||||||
|
duplicateDomains =
|
||||||
self.nixosConfigurations
|
self.nixosConfigurations
|
||||||
|> lib.mapAttrsToList (_: value: value.options.meta.domains.list.definitionsWithLocations)
|
|> lib.mapAttrsToList (_: value: value.options.meta.domains.list.definitionsWithLocations)
|
||||||
|> lib.concatLists
|
|> lib.concatLists
|
||||||
|
|
@ -22,7 +46,7 @@ let
|
||||||
|> lib.filterAttrs (domain: entries: lib.length entries > 1);
|
|> lib.filterAttrs (domain: entries: lib.length entries > 1);
|
||||||
|
|
||||||
errorMessage =
|
errorMessage =
|
||||||
duplicatedDomains
|
duplicateDomains
|
||||||
|> lib.mapAttrsToList (
|
|> lib.mapAttrsToList (
|
||||||
domain: entries:
|
domain: entries:
|
||||||
"Duplicate domain \"${domain}\" found in:\n"
|
"Duplicate domain \"${domain}\" found in:\n"
|
||||||
|
|
@ -30,22 +54,9 @@ let
|
||||||
)
|
)
|
||||||
|> lib.concatStrings;
|
|> lib.concatStrings;
|
||||||
in
|
in
|
||||||
|
[
|
||||||
{
|
{
|
||||||
options.meta.domains = {
|
assertion = duplicateDomains == { };
|
||||||
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;
|
message = errorMessage;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -6,26 +6,6 @@
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
cfg = config.meta.ports;
|
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
|
in
|
||||||
{
|
{
|
||||||
options.meta.ports = {
|
options.meta.ports = {
|
||||||
|
|
@ -40,9 +20,31 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkIf cfg.assertUnique {
|
config = lib.mkIf cfg.assertUnique {
|
||||||
assertions = [
|
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 = duplicatedPorts == { };
|
assertion = duplicatePorts == { };
|
||||||
message = errorMessage;
|
message = errorMessage;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue