mirror of
https://github.com/gensokyo-zone/infrastructure.git
synced 2026-02-09 12:29:19 -08:00
chore: nf-fmt-nix
This commit is contained in:
parent
7486517713
commit
9903866044
160 changed files with 4570 additions and 3019 deletions
|
|
@ -24,7 +24,10 @@
|
|||
...
|
||||
}: let
|
||||
cfg = config.networking.access;
|
||||
addressForAttr = if config.networking.enableIPv6 then "address6ForNetwork" else "address4ForNetwork";
|
||||
addressForAttr =
|
||||
if config.networking.enableIPv6
|
||||
then "address6ForNetwork"
|
||||
else "address4ForNetwork";
|
||||
has'Int = system.network.networks.int.enable or false;
|
||||
has'Local = system.network.networks.local.enable or false;
|
||||
has'Tail' = system.network.networks.tail.enable or false;
|
||||
|
|
@ -48,26 +51,53 @@
|
|||
forSystem = access.systemFor hostName;
|
||||
forSystemHas = network: forSystem.access ? ${addressForAttr}.${network} || forSystem.access ? address4ForNetwork.${network};
|
||||
err = throw "no interface found between ${config.networking.hostName} -> ${hostName}@${network}";
|
||||
fallback = if nameAllowed
|
||||
fallback =
|
||||
if nameAllowed
|
||||
then lib.warn "getAddressFor hostname fallback for ${config.networking.hostName} -> ${hostName}@${network}" (access.getHostnameFor hostName network)
|
||||
else err;
|
||||
local = forSystem.access.${addressForAttr}.local or forSystem.access.address4ForNetwork.local or fallback;
|
||||
int = forSystem.access.${addressForAttr}.int or forSystem.access.address4ForNetwork.int or fallback;
|
||||
tail = forSystem.access.${addressForAttr}.tail or fallback;
|
||||
in {
|
||||
lan =
|
||||
if hostName == system.name then forSystem.access.${addressForAttr}.localhost
|
||||
else if has'Int && forSystemHas "int" then int
|
||||
else if has'Local && forSystemHas "local" then local
|
||||
else fallback;
|
||||
${if has'Local then "local" else null} = local;
|
||||
${if has'Int then "int" else null} = int;
|
||||
${if has'Tail then "tail" else null} = tail;
|
||||
}.${network} or fallback;
|
||||
in
|
||||
{
|
||||
lan =
|
||||
if hostName == system.name
|
||||
then forSystem.access.${addressForAttr}.localhost
|
||||
else if has'Int && forSystemHas "int"
|
||||
then int
|
||||
else if has'Local && forSystemHas "local"
|
||||
then local
|
||||
else fallback;
|
||||
${
|
||||
if has'Local
|
||||
then "local"
|
||||
else null
|
||||
} =
|
||||
local;
|
||||
${
|
||||
if has'Int
|
||||
then "int"
|
||||
else null
|
||||
} =
|
||||
int;
|
||||
${
|
||||
if has'Tail
|
||||
then "tail"
|
||||
else null
|
||||
} =
|
||||
tail;
|
||||
}
|
||||
.${network}
|
||||
or fallback;
|
||||
in {
|
||||
inherit (systemAccess)
|
||||
hostnameForNetwork address4ForNetwork address6ForNetwork
|
||||
systemForService systemForServiceId;
|
||||
inherit
|
||||
(systemAccess)
|
||||
hostnameForNetwork
|
||||
address4ForNetwork
|
||||
address6ForNetwork
|
||||
systemForService
|
||||
systemForServiceId
|
||||
;
|
||||
addressForNetwork = systemAccess.${addressForAttr};
|
||||
systemFor = hostName:
|
||||
if hostName == config.networking.hostName
|
||||
|
|
@ -91,34 +121,63 @@
|
|||
getHostnameFor = hostName: network: let
|
||||
forSystem = access.systemFor hostName;
|
||||
err = throw "no hostname found between ${config.networking.hostName} and ${hostName}@${network}";
|
||||
in {
|
||||
lan =
|
||||
if hostName == system.name then forSystem.access.hostnameForNetwork.localhost
|
||||
else if has'Int && forSystem.access.hostnameForNetwork ? int then forSystem.access.hostnameForNetwork.int
|
||||
else if has'Local && forSystem.access.hostnameForNetwork ? local then forSystem.access.hostnameForNetwork.local
|
||||
else err;
|
||||
${if has'Local then "local" else null} = forSystem.access.hostnameForNetwork.local or err;
|
||||
${if has'Int then "int" else null} = forSystem.access.hostnameForNetwork.int or err;
|
||||
${if has'Tail then "tail" else null} = forSystem.access.hostnameForNetwork.tail or err;
|
||||
}.${network} or err;
|
||||
in
|
||||
{
|
||||
lan =
|
||||
if hostName == system.name
|
||||
then forSystem.access.hostnameForNetwork.localhost
|
||||
else if has'Int && forSystem.access.hostnameForNetwork ? int
|
||||
then forSystem.access.hostnameForNetwork.int
|
||||
else if has'Local && forSystem.access.hostnameForNetwork ? local
|
||||
then forSystem.access.hostnameForNetwork.local
|
||||
else err;
|
||||
${
|
||||
if has'Local
|
||||
then "local"
|
||||
else null
|
||||
} =
|
||||
forSystem.access.hostnameForNetwork.local or err;
|
||||
${
|
||||
if has'Int
|
||||
then "int"
|
||||
else null
|
||||
} =
|
||||
forSystem.access.hostnameForNetwork.int or err;
|
||||
${
|
||||
if has'Tail
|
||||
then "tail"
|
||||
else null
|
||||
} =
|
||||
forSystem.access.hostnameForNetwork.tail or err;
|
||||
}
|
||||
.${network}
|
||||
or err;
|
||||
proxyUrlFor = {
|
||||
system ? if serviceId != null then access.systemForServiceId serviceId else access.systemForService serviceName,
|
||||
system ?
|
||||
if serviceId != null
|
||||
then access.systemForServiceId serviceId
|
||||
else access.systemForService serviceName,
|
||||
serviceName ? mapNullable (serviceId: (findSingle (s: s.id == serviceId) null null (attrValues system.exports.services)).name) serviceId,
|
||||
serviceId ? null,
|
||||
service ? system.exports.services.${serviceName},
|
||||
portName ? "default",
|
||||
network ? "lan",
|
||||
scheme ? null,
|
||||
getAddressFor ? "getAddressFor"
|
||||
getAddressFor ? "getAddressFor",
|
||||
}: let
|
||||
port = service.ports.${portName};
|
||||
scheme' = if scheme == null then port.protocol else scheme;
|
||||
port' = if !port.enable
|
||||
scheme' =
|
||||
if scheme == null
|
||||
then port.protocol
|
||||
else scheme;
|
||||
port' =
|
||||
if !port.enable
|
||||
then throw "${system.name}.exports.services.${service.name}.ports.${portName} isn't enabled"
|
||||
else ":${toString port.port}";
|
||||
host = access.${getAddressFor} system.name network;
|
||||
url = "${scheme'}://${mkAddress6 host}${port'}";
|
||||
in assert service.enable; url;
|
||||
in
|
||||
assert service.enable; url;
|
||||
};
|
||||
};
|
||||
networking.tempAddresses = mkIf cfg.global.enable (
|
||||
|
|
@ -142,9 +201,11 @@ in {
|
|||
default = domain;
|
||||
};
|
||||
global.enable = mkEnableOption "globally routeable";
|
||||
online.enable = mkEnableOption "a deployed machine" // {
|
||||
default = true;
|
||||
};
|
||||
online.enable =
|
||||
mkEnableOption "a deployed machine"
|
||||
// {
|
||||
default = true;
|
||||
};
|
||||
hostnameForNetwork = mkOption {
|
||||
type = attrsOf str;
|
||||
default = {};
|
||||
|
|
@ -164,7 +225,12 @@ in {
|
|||
];
|
||||
|
||||
access = let
|
||||
noNetwork = { enable = false; address4 = null; address6 = null; fqdn = null; };
|
||||
noNetwork = {
|
||||
enable = false;
|
||||
address4 = null;
|
||||
address6 = null;
|
||||
fqdn = null;
|
||||
};
|
||||
local = config.network.networks.local or noNetwork;
|
||||
int = config.network.networks.int or noNetwork;
|
||||
mapNetwork' = mkDefault: attr: network: mkIf (network.enable && network.${attr} != null) (mkDefault network.${attr});
|
||||
|
|
@ -216,12 +282,14 @@ in {
|
|||
hasService = system: system.config.exports.services.${service}.enable;
|
||||
notFound = throw "no system found serving ${service}";
|
||||
multiple = throw "multiple systems found serving ${service}";
|
||||
in (findSingle hasService notFound multiple (attrValues systems)).config;
|
||||
in
|
||||
(findSingle hasService notFound multiple (attrValues systems)).config;
|
||||
systemForServiceId = serviceId: let
|
||||
hasService = system: findSingle (service: service.id == serviceId && service.enable) null multiple (attrValues system.config.exports.services) != null;
|
||||
notFound = throw "no system found serving ${serviceId}";
|
||||
multiple = throw "multiple systems found serving ${serviceId}";
|
||||
in (findSingle hasService notFound multiple (attrValues systems)).config;
|
||||
in
|
||||
(findSingle hasService notFound multiple (attrValues systems)).config;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue