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;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,9 +10,11 @@
|
|||
inherit (lib.modules) mkIf mkOptionDefault;
|
||||
in {
|
||||
options.ci = with lib.types; {
|
||||
enable = mkEnableOption "build via CI" // {
|
||||
default = config.type == "NixOS";
|
||||
};
|
||||
enable =
|
||||
mkEnableOption "build via CI"
|
||||
// {
|
||||
default = config.type == "NixOS";
|
||||
};
|
||||
allowFailure = mkOption {
|
||||
type = bool;
|
||||
default = false;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
{lib, gensokyo-zone, ...}: let
|
||||
{
|
||||
lib,
|
||||
gensokyo-zone,
|
||||
...
|
||||
}: let
|
||||
inherit (gensokyo-zone.lib) mapAlmostOptionDefaults mkAlmostOptionDefault;
|
||||
inherit (lib.attrsets) mapAttrs;
|
||||
in {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
{lib, gensokyo-zone, ...}: let
|
||||
{
|
||||
lib,
|
||||
gensokyo-zone,
|
||||
...
|
||||
}: let
|
||||
inherit (gensokyo-zone.lib) mapAlmostOptionDefaults mkAlmostOptionDefault;
|
||||
inherit (lib.attrsets) mapAttrs;
|
||||
in {
|
||||
config.exports.services.dnsmasq = { config, ... }: {
|
||||
config.exports.services.dnsmasq = {config, ...}: {
|
||||
id = mkAlmostOptionDefault "dns";
|
||||
nixos = {
|
||||
serviceAttr = "dnsmasq";
|
||||
|
|
|
|||
|
|
@ -24,7 +24,12 @@
|
|||
};
|
||||
id = mkOption {
|
||||
type = str;
|
||||
default = cfg.services.${config.serviceName}.id/* or config.name*/;
|
||||
default =
|
||||
cfg.services.${config.serviceName}.id
|
||||
/*
|
||||
or config.name
|
||||
*/
|
||||
;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
{lib, gensokyo-zone, ...}: let
|
||||
{
|
||||
lib,
|
||||
gensokyo-zone,
|
||||
...
|
||||
}: let
|
||||
inherit (gensokyo-zone.lib) mapAlmostOptionDefaults mkAlmostOptionDefault;
|
||||
inherit (lib.attrsets) mapAttrs;
|
||||
in {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
{lib, gensokyo-zone, ...}: let
|
||||
{
|
||||
lib,
|
||||
gensokyo-zone,
|
||||
...
|
||||
}: let
|
||||
inherit (gensokyo-zone.lib) mapAlmostOptionDefaults mkAlmostOptionDefault;
|
||||
inherit (lib.attrsets) mapAttrs;
|
||||
in {
|
||||
|
|
|
|||
|
|
@ -1,14 +1,19 @@
|
|||
{lib, gensokyo-zone, ...}: let
|
||||
{
|
||||
lib,
|
||||
gensokyo-zone,
|
||||
...
|
||||
}: let
|
||||
inherit (gensokyo-zone.lib) mapAlmostOptionDefaults mkAlmostOptionDefault;
|
||||
inherit (lib.modules) mkIf;
|
||||
inherit (lib.attrsets) mapAttrs;
|
||||
inherit (lib.lists) all imap0;
|
||||
inherit (lib.trivial) id;
|
||||
in {
|
||||
config.exports.services.home-assistant = { config, ... }: let
|
||||
config.exports.services.home-assistant = {config, ...}: let
|
||||
mkAssertion = f: nixosConfig: let
|
||||
cfg = nixosConfig.services.home-assistant;
|
||||
in f nixosConfig cfg;
|
||||
in
|
||||
f nixosConfig cfg;
|
||||
assertPort = nixosConfig: cfg: {
|
||||
assertion = config.ports.default.port == cfg.config.http.server_port;
|
||||
message = "port mismatch";
|
||||
|
|
@ -16,10 +21,11 @@ in {
|
|||
assertHomekitPort = let
|
||||
portName = i: "homekit${toString i}";
|
||||
mkAssertPort = i: homekit: config.ports.${portName i}.port or null == homekit.port;
|
||||
in nixosConfig: cfg: {
|
||||
assertion = all id (imap0 mkAssertPort cfg.config.homekit);
|
||||
message = "homekit port mismatch";
|
||||
};
|
||||
in
|
||||
nixosConfig: cfg: {
|
||||
assertion = all id (imap0 mkAssertPort cfg.config.homekit);
|
||||
message = "homekit port mismatch";
|
||||
};
|
||||
in {
|
||||
id = mkAlmostOptionDefault "home";
|
||||
nixos = {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
{lib, gensokyo-zone, ...}: let
|
||||
{
|
||||
lib,
|
||||
gensokyo-zone,
|
||||
...
|
||||
}: let
|
||||
inherit (gensokyo-zone.lib) mapAlmostOptionDefaults mkAlmostOptionDefault;
|
||||
inherit (lib.modules) mkIf;
|
||||
in {
|
||||
config.exports.services.invidious = { config, ... }: {
|
||||
config.exports.services.invidious = {config, ...}: {
|
||||
id = mkAlmostOptionDefault "yt";
|
||||
nixos = {
|
||||
serviceAttr = "invidious";
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
{lib, gensokyo-zone, ...}: let
|
||||
{
|
||||
lib,
|
||||
gensokyo-zone,
|
||||
...
|
||||
}: let
|
||||
inherit (gensokyo-zone.lib) mapAlmostOptionDefaults;
|
||||
inherit (lib.attrsets) mapAttrs;
|
||||
in {
|
||||
config.exports.services.kerberos = { config, ... }: {
|
||||
config.exports.services.kerberos = {config, ...}: {
|
||||
id = "krb5";
|
||||
ports = mapAttrs (_: mapAlmostOptionDefaults) {
|
||||
default = {
|
||||
|
|
|
|||
|
|
@ -1,26 +1,32 @@
|
|||
{lib, gensokyo-zone, ...}: let
|
||||
{
|
||||
lib,
|
||||
gensokyo-zone,
|
||||
...
|
||||
}: let
|
||||
inherit (gensokyo-zone.lib) mapAlmostOptionDefaults mkAlmostOptionDefault;
|
||||
inherit (lib.modules) mkIf;
|
||||
inherit (lib.attrsets) mapAttrs;
|
||||
in {
|
||||
config.exports.services.keycloak = { config, ... }: {
|
||||
config.exports.services.keycloak = {config, ...}: {
|
||||
id = mkAlmostOptionDefault "sso";
|
||||
nixos = {
|
||||
serviceAttr = "keycloak";
|
||||
assertions = let
|
||||
mkAssertion = f: nixosConfig: let
|
||||
cfg = nixosConfig.services.keycloak;
|
||||
in f nixosConfig cfg;
|
||||
in mkIf config.enable [
|
||||
(mkAssertion (nixosConfig: cfg: {
|
||||
assertion = config.ports.${cfg.protocol}.port == cfg.port;
|
||||
message = "port mismatch";
|
||||
}))
|
||||
(mkAssertion (nixosConfig: cfg: {
|
||||
assertion = config.ports.${cfg.protocol}.enable;
|
||||
message = "port enable mismatch";
|
||||
}))
|
||||
];
|
||||
in
|
||||
f nixosConfig cfg;
|
||||
in
|
||||
mkIf config.enable [
|
||||
(mkAssertion (nixosConfig: cfg: {
|
||||
assertion = config.ports.${cfg.protocol}.port == cfg.port;
|
||||
message = "port mismatch";
|
||||
}))
|
||||
(mkAssertion (nixosConfig: cfg: {
|
||||
assertion = config.ports.${cfg.protocol}.enable;
|
||||
message = "port enable mismatch";
|
||||
}))
|
||||
];
|
||||
};
|
||||
ports = mapAttrs (_: mapAlmostOptionDefaults) {
|
||||
http = {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
{lib, gensokyo-zone, ...}: let
|
||||
{
|
||||
lib,
|
||||
gensokyo-zone,
|
||||
...
|
||||
}: let
|
||||
inherit (gensokyo-zone.lib) mapAlmostOptionDefaults mkAlmostOptionDefault;
|
||||
inherit (lib.attrsets) mapAttrs;
|
||||
in {
|
||||
config.exports.services.ldap = { config, ... }: {
|
||||
config.exports.services.ldap = {config, ...}: {
|
||||
defaults.port.listen = mkAlmostOptionDefault "lan";
|
||||
ports = mapAttrs (_: mapAlmostOptionDefaults) {
|
||||
default = {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,17 @@
|
|||
{lib, gensokyo-zone, ...}: let
|
||||
{
|
||||
lib,
|
||||
gensokyo-zone,
|
||||
...
|
||||
}: let
|
||||
inherit (gensokyo-zone.lib) mapAlmostOptionDefaults mkAlmostOptionDefault;
|
||||
inherit (lib.modules) mkIf;
|
||||
inherit (lib.attrsets) mapAttrs;
|
||||
in {
|
||||
config.exports.services.minecraft-bedrock-server = { config, ... }: let
|
||||
config.exports.services.minecraft-bedrock-server = {config, ...}: let
|
||||
mkAssertion = f: nixosConfig: let
|
||||
cfg = nixosConfig.services.minecraft-bedrock-server;
|
||||
in f nixosConfig cfg;
|
||||
in
|
||||
f nixosConfig cfg;
|
||||
in {
|
||||
nixos = {
|
||||
serviceAttr = "minecraft-bedrock-server";
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
{lib, gensokyo-zone, ...}: let
|
||||
{
|
||||
lib,
|
||||
gensokyo-zone,
|
||||
...
|
||||
}: let
|
||||
inherit (gensokyo-zone.lib) mapAlmostOptionDefaults mkAlmostOptionDefault;
|
||||
inherit (lib.modules) mkIf;
|
||||
inherit (lib.attrsets) mapAttrs;
|
||||
inherit (lib.lists) all imap0;
|
||||
inherit (lib.trivial) id;
|
||||
in {
|
||||
config.exports.services.mosquitto = { config, ... }: {
|
||||
config.exports.services.mosquitto = {config, ...}: {
|
||||
id = mkAlmostOptionDefault "mqtt";
|
||||
nixos = {
|
||||
serviceAttr = "mosquitto";
|
||||
|
|
@ -13,7 +17,8 @@ in {
|
|||
(nixosConfig: let
|
||||
cfg = nixosConfig.services.mosquitto;
|
||||
portName = i:
|
||||
if i == 0 then "default"
|
||||
if i == 0
|
||||
then "default"
|
||||
else "listener${toString i}";
|
||||
mkAssertPort = i: listener: config.ports.${portName i}.port or null == listener.port;
|
||||
in {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
{lib, gensokyo-zone, ...}: let
|
||||
{
|
||||
lib,
|
||||
gensokyo-zone,
|
||||
...
|
||||
}: let
|
||||
inherit (gensokyo-zone.lib) mapAlmostOptionDefaults mkAlmostOptionDefault;
|
||||
inherit (lib.attrsets) mapAttrs;
|
||||
in {
|
||||
config.exports.services.motion = { config, ... }: {
|
||||
config.exports.services.motion = {config, ...}: {
|
||||
defaults.port.listen = mkAlmostOptionDefault "lan";
|
||||
ports = mapAttrs (_: mapAlmostOptionDefaults) {
|
||||
default = {
|
||||
|
|
|
|||
|
|
@ -1,24 +1,34 @@
|
|||
{lib, gensokyo-zone, ...}: let
|
||||
{
|
||||
lib,
|
||||
gensokyo-zone,
|
||||
...
|
||||
}: let
|
||||
inherit (gensokyo-zone.lib) mapAlmostOptionDefaults mkAlmostOptionDefault;
|
||||
inherit (lib.modules) mkIf;
|
||||
inherit (lib.attrsets) mapAttrs;
|
||||
in {
|
||||
config.exports.services.nfs = { config, ... }: let
|
||||
config.exports.services.nfs = {config, ...}: let
|
||||
mkAssertion = f: nixosConfig: let
|
||||
cfg = nixosConfig.services.nfs;
|
||||
in f nixosConfig cfg;
|
||||
mkAssertionPort = portName: mkAssertion (nixosConfig: cfg: let
|
||||
portAttr = "${portName}Port";
|
||||
in {
|
||||
assertion = mkAssertPort config.ports.${portName} cfg.server.${portAttr};
|
||||
message = "${portAttr} mismatch";
|
||||
});
|
||||
in
|
||||
f nixosConfig cfg;
|
||||
mkAssertionPort = portName:
|
||||
mkAssertion (nixosConfig: cfg: let
|
||||
portAttr = "${portName}Port";
|
||||
in {
|
||||
assertion = mkAssertPort config.ports.${portName} cfg.server.${portAttr};
|
||||
message = "${portAttr} mismatch";
|
||||
});
|
||||
mkAssertPort = port: cfgPort: let
|
||||
cmpPort = if port.enable then port.port else null;
|
||||
in cfgPort == cmpPort;
|
||||
cmpPort =
|
||||
if port.enable
|
||||
then port.port
|
||||
else null;
|
||||
in
|
||||
cfgPort == cmpPort;
|
||||
in {
|
||||
nixos = {
|
||||
serviceAttrPath = [ "services" "nfs" "server" ];
|
||||
serviceAttrPath = ["services" "nfs" "server"];
|
||||
assertions = mkIf config.enable [
|
||||
(mkAssertionPort "statd")
|
||||
(mkAssertionPort "lockd")
|
||||
|
|
|
|||
|
|
@ -1,12 +1,17 @@
|
|||
{lib, gensokyo-zone, ...}: let
|
||||
{
|
||||
lib,
|
||||
gensokyo-zone,
|
||||
...
|
||||
}: let
|
||||
inherit (gensokyo-zone.lib) mapAlmostOptionDefaults mkAlmostOptionDefault;
|
||||
inherit (lib.modules) mkIf;
|
||||
inherit (lib.attrsets) mapAttrs;
|
||||
in {
|
||||
config.exports.services.nginx = { config, ... }: let
|
||||
config.exports.services.nginx = {config, ...}: let
|
||||
mkAssertion = f: nixosConfig: let
|
||||
cfg = nixosConfig.services.nginx;
|
||||
in f nixosConfig cfg;
|
||||
in
|
||||
f nixosConfig cfg;
|
||||
assertPorts = nixosConfig: cfg: {
|
||||
assertion = config.ports.http.port == cfg.defaultHTTPListenPort && config.ports.https.port == cfg.defaultSSLListenPort;
|
||||
message = "ports mismatch";
|
||||
|
|
|
|||
|
|
@ -1,22 +1,28 @@
|
|||
{lib, gensokyo-zone, ...}: let
|
||||
{
|
||||
lib,
|
||||
gensokyo-zone,
|
||||
...
|
||||
}: let
|
||||
inherit (gensokyo-zone.lib) mapAlmostOptionDefaults mkAlmostOptionDefault;
|
||||
inherit (lib.modules) mkIf;
|
||||
inherit (lib.attrsets) mapAttrs;
|
||||
in {
|
||||
config.exports.services.openwebrx = { config, ... }: {
|
||||
config.exports.services.openwebrx = {config, ...}: {
|
||||
id = mkAlmostOptionDefault "webrx";
|
||||
nixos = {
|
||||
serviceAttr = "openwebrx";
|
||||
assertions = let
|
||||
mkAssertion = f: nixosConfig: let
|
||||
cfg = nixosConfig.services.openwebrx;
|
||||
in f nixosConfig cfg;
|
||||
in mkIf config.enable [
|
||||
(mkAssertion (nixosConfig: cfg: {
|
||||
assertion = config.ports.default.port == cfg.port;
|
||||
message = "port mismatch";
|
||||
}))
|
||||
];
|
||||
in
|
||||
f nixosConfig cfg;
|
||||
in
|
||||
mkIf config.enable [
|
||||
(mkAssertion (nixosConfig: cfg: {
|
||||
assertion = config.ports.default.port == cfg.port;
|
||||
message = "port mismatch";
|
||||
}))
|
||||
];
|
||||
};
|
||||
defaults.port.listen = mkAlmostOptionDefault "lan";
|
||||
ports = mapAttrs (_: mapAlmostOptionDefaults) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
{lib, gensokyo-zone, ...}: let
|
||||
{
|
||||
lib,
|
||||
gensokyo-zone,
|
||||
...
|
||||
}: let
|
||||
inherit (gensokyo-zone.lib) mapAlmostOptionDefaults mkAlmostOptionDefault;
|
||||
inherit (lib.attrsets) mapAttrs;
|
||||
in {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,16 @@
|
|||
{lib, gensokyo-zone, ...}: let
|
||||
{
|
||||
lib,
|
||||
gensokyo-zone,
|
||||
...
|
||||
}: let
|
||||
inherit (gensokyo-zone.lib) mapAlmostOptionDefaults;
|
||||
inherit (lib.modules) mkIf;
|
||||
in {
|
||||
config.exports.services.postgresql = { config, ... }: let
|
||||
config.exports.services.postgresql = {config, ...}: let
|
||||
mkAssertion = f: nixosConfig: let
|
||||
cfg = nixosConfig.services.postgresql;
|
||||
in f nixosConfig cfg;
|
||||
in
|
||||
f nixosConfig cfg;
|
||||
in {
|
||||
nixos = {
|
||||
serviceAttr = "postgresql";
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
{lib, gensokyo-zone, ...}: let
|
||||
{
|
||||
lib,
|
||||
gensokyo-zone,
|
||||
...
|
||||
}: let
|
||||
inherit (gensokyo-zone.lib) mapAlmostOptionDefaults mkAlmostOptionDefault;
|
||||
in {
|
||||
config.exports.services.proxmox = { config, ... }: {
|
||||
config.exports.services.proxmox = {config, ...}: {
|
||||
id = mkAlmostOptionDefault "prox";
|
||||
defaults.port.listen = mkAlmostOptionDefault "lan";
|
||||
ports.default = mapAlmostOptionDefaults {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
{lib, gensokyo-zone, ...}: let
|
||||
{
|
||||
lib,
|
||||
gensokyo-zone,
|
||||
...
|
||||
}: let
|
||||
inherit (gensokyo-zone.lib) mapAlmostOptionDefaults mkAlmostOptionDefault;
|
||||
inherit (lib.attrsets) mapAttrs;
|
||||
in {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,11 @@
|
|||
inherit (lib.trivial) mapNullable;
|
||||
inherit (lib.strings) concatStringsSep;
|
||||
systemConfig = config;
|
||||
portModule = {config, service, ...}: {
|
||||
portModule = {
|
||||
config,
|
||||
service,
|
||||
...
|
||||
}: {
|
||||
options = with lib.types; {
|
||||
enable =
|
||||
mkEnableOption "port"
|
||||
|
|
@ -86,7 +90,7 @@
|
|||
};
|
||||
assertions = mkOption {
|
||||
type = listOf (functionTo attrs);
|
||||
default = [ ];
|
||||
default = [];
|
||||
};
|
||||
};
|
||||
defaults = {
|
||||
|
|
@ -107,7 +111,8 @@
|
|||
serviceConfig = getAttrFromPath config.nixos.serviceAttrPath;
|
||||
mkAssertion = f: nixosConfig: let
|
||||
cfg = serviceConfig nixosConfig;
|
||||
in f nixosConfig cfg;
|
||||
in
|
||||
f nixosConfig cfg;
|
||||
enableAssertion = nixosConfig: cfg: {
|
||||
assertion = (! cfg ? enable) || (config.enable == cfg.enable);
|
||||
message = "enable == nixosConfig.${concatStringsSep "." config.nixos.serviceAttrPath}.enable";
|
||||
|
|
@ -120,12 +125,18 @@
|
|||
};
|
||||
};
|
||||
};
|
||||
nixosModule = {config, system, ...}: let
|
||||
nixosModule = {
|
||||
config,
|
||||
system,
|
||||
...
|
||||
}: let
|
||||
mapAssertion = service: a: let
|
||||
res = a config;
|
||||
in res // {
|
||||
message = "system.exports.${service.name}: " + res.message or "assertion failed";
|
||||
};
|
||||
in
|
||||
res
|
||||
// {
|
||||
message = "system.exports.${service.name}: " + res.message or "assertion failed";
|
||||
};
|
||||
assertions = mapAttrsToList (_: service: map (mapAssertion service) service.nixos.assertions) system.exports.services;
|
||||
in {
|
||||
config = {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,18 @@
|
|||
{lib, gensokyo-zone, ...}: let
|
||||
{
|
||||
lib,
|
||||
gensokyo-zone,
|
||||
...
|
||||
}: let
|
||||
inherit (gensokyo-zone.lib) mapAlmostOptionDefaults mkAlmostOptionDefault;
|
||||
inherit (lib.modules) mkIf;
|
||||
inherit (lib.attrsets) mapAttrs filterAttrs mapAttrsToList;
|
||||
inherit (lib.lists) sort;
|
||||
in {
|
||||
config.exports.services.sshd = { config, ... }: let
|
||||
config.exports.services.sshd = {config, ...}: let
|
||||
mkAssertion = f: nixosConfig: let
|
||||
cfg = nixosConfig.services.openssh;
|
||||
in f nixosConfig cfg;
|
||||
in
|
||||
f nixosConfig cfg;
|
||||
sorted = sort (a: b: a > b);
|
||||
assertPorts = nixosConfig: cfg: let
|
||||
nixosPorts = cfg.ports;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
{lib, gensokyo-zone, ...}: let
|
||||
{
|
||||
lib,
|
||||
gensokyo-zone,
|
||||
...
|
||||
}: let
|
||||
inherit (gensokyo-zone.lib) mapAlmostOptionDefaults mkAlmostOptionDefault;
|
||||
inherit (lib.attrsets) mapAttrs;
|
||||
in {
|
||||
config.exports.services.unifi = { config, ... }: {
|
||||
config.exports.services.unifi = {config, ...}: {
|
||||
nixos.serviceAttr = "unifi";
|
||||
defaults.port.listen = mkAlmostOptionDefault "lan";
|
||||
ports = mapAttrs (_: mapAlmostOptionDefaults) {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
{lib, gensokyo-zone, ...}: let
|
||||
{
|
||||
lib,
|
||||
gensokyo-zone,
|
||||
...
|
||||
}: let
|
||||
inherit (gensokyo-zone.lib) mapAlmostOptionDefaults mkAlmostOptionDefault;
|
||||
inherit (lib.modules) mkIf;
|
||||
in {
|
||||
config.exports.services.vouch-proxy = { config, ... }: {
|
||||
config.exports.services.vouch-proxy = {config, ...}: {
|
||||
id = mkAlmostOptionDefault "login";
|
||||
defaults.port.listen = mkAlmostOptionDefault "localhost";
|
||||
nixos = {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
{lib, gensokyo-zone, ...}: let
|
||||
{
|
||||
lib,
|
||||
gensokyo-zone,
|
||||
...
|
||||
}: let
|
||||
inherit (gensokyo-zone.lib) mapAlmostOptionDefaults mkAlmostOptionDefault;
|
||||
inherit (lib.modules) mkIf;
|
||||
in {
|
||||
config.exports.services.zigbee2mqtt = { config, ... }: {
|
||||
config.exports.services.zigbee2mqtt = {config, ...}: {
|
||||
id = mkAlmostOptionDefault "z2m";
|
||||
nixos = {
|
||||
serviceAttr = "zigbee2mqtt";
|
||||
|
|
|
|||
62
modules/system/extern/files.nix
vendored
62
modules/system/extern/files.nix
vendored
|
|
@ -1,13 +1,21 @@
|
|||
let
|
||||
fileModule = {config, name, gensokyo-zone, lib, ...}: let
|
||||
fileModule = {
|
||||
config,
|
||||
name,
|
||||
gensokyo-zone,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib.options) mkOption mkEnableOption;
|
||||
inherit (lib.modules) mkOptionDefault;
|
||||
inherit (lib.strings) hasPrefix removePrefix;
|
||||
in {
|
||||
options = with lib.types; {
|
||||
enable = mkEnableOption "external file" // {
|
||||
default = true;
|
||||
};
|
||||
enable =
|
||||
mkEnableOption "external file"
|
||||
// {
|
||||
default = true;
|
||||
};
|
||||
path = mkOption {
|
||||
type = str;
|
||||
default = name;
|
||||
|
|
@ -35,25 +43,33 @@ let
|
|||
relativeSource = let
|
||||
flakeRoot = toString gensokyo-zone.self + "/";
|
||||
sourcePath = toString config.source;
|
||||
in mkOptionDefault (
|
||||
if hasPrefix flakeRoot sourcePath then removePrefix flakeRoot sourcePath
|
||||
else null
|
||||
);
|
||||
in
|
||||
mkOptionDefault (
|
||||
if hasPrefix flakeRoot sourcePath
|
||||
then removePrefix flakeRoot sourcePath
|
||||
else null
|
||||
);
|
||||
};
|
||||
};
|
||||
in {config, gensokyo-zone, lib, ...}: let
|
||||
inherit (lib.options) mkOption;
|
||||
in {
|
||||
options.extern = with lib.types; {
|
||||
files = mkOption {
|
||||
type = attrsOf (submoduleWith {
|
||||
modules = [ fileModule ];
|
||||
specialArgs = {
|
||||
inherit gensokyo-zone;
|
||||
system = config;
|
||||
};
|
||||
});
|
||||
default = { };
|
||||
in
|
||||
{
|
||||
config,
|
||||
gensokyo-zone,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib.options) mkOption;
|
||||
in {
|
||||
options.extern = with lib.types; {
|
||||
files = mkOption {
|
||||
type = attrsOf (submoduleWith {
|
||||
modules = [fileModule];
|
||||
specialArgs = {
|
||||
inherit gensokyo-zone;
|
||||
system = config;
|
||||
};
|
||||
});
|
||||
default = {};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ in {
|
|||
};
|
||||
modules = mkOption {
|
||||
type = listOf unspecified;
|
||||
default = [ ];
|
||||
default = [];
|
||||
};
|
||||
specialArgs = mkOption {
|
||||
type = attrs;
|
||||
|
|
@ -101,10 +101,13 @@ in {
|
|||
darwin = inputs.darwin.lib.darwinSystem;
|
||||
macos = inputs.darwin.lib.darwinSystem;
|
||||
}
|
||||
.${string.toLower config.type} or null;
|
||||
built = mkOptionDefault (mapNullable (builder: builder {
|
||||
inherit (config) system modules specialArgs;
|
||||
}) config.builder);
|
||||
.${string.toLower config.type}
|
||||
or null;
|
||||
built = mkOptionDefault (mapNullable (builder:
|
||||
builder {
|
||||
inherit (config) system modules specialArgs;
|
||||
})
|
||||
config.builder);
|
||||
specialArgs = {
|
||||
inherit name inputs std Std meta;
|
||||
inherit (inputs.self.lib) gensokyo-zone;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,19 @@
|
|||
{config, lib, inputs, ...}: let
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
inputs,
|
||||
...
|
||||
}: let
|
||||
inherit (inputs.self.lib.lib) eui64;
|
||||
inherit (lib.options) mkOption mkEnableOption;
|
||||
inherit (lib.modules) mkIf mkOptionDefault;
|
||||
inherit (lib.trivial) mapNullable;
|
||||
networkModule = { config, name, system, ... }: let
|
||||
networkModule = {
|
||||
config,
|
||||
name,
|
||||
system,
|
||||
...
|
||||
}: let
|
||||
knownNetworks = {
|
||||
local.slaac = {
|
||||
enable = true;
|
||||
|
|
@ -13,9 +23,11 @@
|
|||
};
|
||||
in {
|
||||
options = with lib.types; {
|
||||
enable = mkEnableOption "network" // {
|
||||
default = true;
|
||||
};
|
||||
enable =
|
||||
mkEnableOption "network"
|
||||
// {
|
||||
default = true;
|
||||
};
|
||||
slaac = {
|
||||
enable = mkOption {
|
||||
type = bool;
|
||||
|
|
@ -65,12 +77,12 @@ in {
|
|||
options.network = with lib.types; {
|
||||
networks = mkOption {
|
||||
type = attrsOf (submoduleWith {
|
||||
modules = [ networkModule ];
|
||||
modules = [networkModule];
|
||||
specialArgs = {
|
||||
system = config;
|
||||
};
|
||||
});
|
||||
default = { };
|
||||
default = {};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
{config, lib, ...}: let
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib.options) mkOption mkEnableOption;
|
||||
cfg = config.proxmox.container;
|
||||
in {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,10 @@
|
|||
{config, gensokyo-zone, lib, Std, ...}: let
|
||||
{
|
||||
config,
|
||||
gensokyo-zone,
|
||||
lib,
|
||||
Std,
|
||||
...
|
||||
}: let
|
||||
inherit (Std) UInt;
|
||||
inherit (gensokyo-zone.lib) unmerged eui64 mkAlmostOptionDefault mapAlmostOptionDefaults;
|
||||
inherit (lib.options) mkOption mkEnableOption;
|
||||
|
|
@ -9,11 +15,18 @@
|
|||
inherit (lib.trivial) mapNullable;
|
||||
cfg = config.proxmox.network;
|
||||
internalOffset = 32;
|
||||
networkInterfaceModule = { config, name, system, ... }: {
|
||||
networkInterfaceModule = {
|
||||
config,
|
||||
name,
|
||||
system,
|
||||
...
|
||||
}: {
|
||||
options = with lib.types; {
|
||||
enable = mkEnableOption "network interface" // {
|
||||
default = true;
|
||||
};
|
||||
enable =
|
||||
mkEnableOption "network interface"
|
||||
// {
|
||||
default = true;
|
||||
};
|
||||
bridge = mkOption {
|
||||
type = str;
|
||||
default = "vmbr0";
|
||||
|
|
@ -30,7 +43,7 @@
|
|||
default = null;
|
||||
};
|
||||
address4 = mkOption {
|
||||
type = nullOr (either (enum [ "dhcp" ]) str);
|
||||
type = nullOr (either (enum ["dhcp"]) str);
|
||||
default = null;
|
||||
};
|
||||
gateway4 = mkOption {
|
||||
|
|
@ -38,7 +51,7 @@
|
|||
default = null;
|
||||
};
|
||||
address6 = mkOption {
|
||||
type = nullOr (either (enum [ "auto" "dhcp" ]) str);
|
||||
type = nullOr (either (enum ["auto" "dhcp"]) str);
|
||||
default = null;
|
||||
};
|
||||
gateway6 = mkOption {
|
||||
|
|
@ -47,13 +60,15 @@
|
|||
};
|
||||
firewall.enable = mkEnableOption "firewall";
|
||||
vm.model = mkOption {
|
||||
type = enum [ "virtio" "e1000" "rtl8139" "vmxnet3" ];
|
||||
type = enum ["virtio" "e1000" "rtl8139" "vmxnet3"];
|
||||
default = "virtio";
|
||||
};
|
||||
mdns = {
|
||||
enable = mkEnableOption "mDNS" // {
|
||||
default = config.local.enable && config.id == "net0";
|
||||
};
|
||||
enable =
|
||||
mkEnableOption "mDNS"
|
||||
// {
|
||||
default = config.local.enable && config.id == "net0";
|
||||
};
|
||||
};
|
||||
slaac = {
|
||||
postfix = mkOption {
|
||||
|
|
@ -76,9 +91,11 @@
|
|||
};
|
||||
};
|
||||
networkd = {
|
||||
enable = mkEnableOption "systemd.network" // {
|
||||
default = true;
|
||||
};
|
||||
enable =
|
||||
mkEnableOption "systemd.network"
|
||||
// {
|
||||
default = true;
|
||||
};
|
||||
name = mkOption {
|
||||
type = str;
|
||||
default = config.name;
|
||||
|
|
@ -90,14 +107,20 @@
|
|||
};
|
||||
};
|
||||
config = let
|
||||
hasAddr4 = ! elem config.address4 [ null "dhcp" ];
|
||||
hasAddr6 = ! elem config.address6 [ null "dhcp" "auto" ];
|
||||
hasAddr4 = ! elem config.address4 [null "dhcp"];
|
||||
hasAddr6 = ! elem config.address6 [null "dhcp" "auto"];
|
||||
conf = {
|
||||
local = mkIf config.local.enable {
|
||||
address4 = mkOptionDefault (if hasAddr4 then config.address4 else null);
|
||||
address4 = mkOptionDefault (
|
||||
if hasAddr4
|
||||
then config.address4
|
||||
else null
|
||||
);
|
||||
address6 = mkOptionDefault (
|
||||
if config.address6 == "auto" && config.slaac.postfix != null then "fd0a::${config.slaac.postfix}"
|
||||
else if hasAddr6 then config.address6
|
||||
if config.address6 == "auto" && config.slaac.postfix != null
|
||||
then "fd0a::${config.slaac.postfix}"
|
||||
else if hasAddr6
|
||||
then config.address6
|
||||
else null
|
||||
);
|
||||
};
|
||||
|
|
@ -123,7 +146,7 @@
|
|||
Type = mkOptionDefault "ether";
|
||||
};
|
||||
linkConfig = mkMerge [
|
||||
(mkIf config.mdns.enable { Multicast = mkOptionDefault true; })
|
||||
(mkIf config.mdns.enable {Multicast = mkOptionDefault true;})
|
||||
];
|
||||
networkConfig = mkMerge [
|
||||
(mkIf (config.address6 == "auto") {
|
||||
|
|
@ -134,17 +157,20 @@
|
|||
})
|
||||
];
|
||||
address = mkMerge [
|
||||
(mkIf (! elem config.address4 [ null "dhcp" ]) [ config.address4 ])
|
||||
(mkIf (! elem config.address6 [ null "auto" "dhcp" ]) [ config.address6 ])
|
||||
(mkIf (! elem config.address4 [null "dhcp"]) [config.address4])
|
||||
(mkIf (! elem config.address6 [null "auto" "dhcp"]) [config.address6])
|
||||
];
|
||||
gateway = mkMerge [
|
||||
(mkIf (config.gateway4 != null) [ config.gateway4 ])
|
||||
(mkIf (config.gateway6 != null) [ config.gateway6 ])
|
||||
(mkIf (config.gateway4 != null) [config.gateway4])
|
||||
(mkIf (config.gateway6 != null) [config.gateway6])
|
||||
];
|
||||
DHCP = mkAlmostOptionDefault (
|
||||
if config.address4 == "dhcp" && config.address6 == "dhcp" then "yes"
|
||||
else if config.address6 == "dhcp" then "ipv6"
|
||||
else if config.address4 == "dhcp" then "ipv4"
|
||||
if config.address4 == "dhcp" && config.address6 == "dhcp"
|
||||
then "yes"
|
||||
else if config.address6 == "dhcp"
|
||||
then "ipv6"
|
||||
else if config.address4 == "dhcp"
|
||||
then "ipv4"
|
||||
else "no"
|
||||
);
|
||||
};
|
||||
|
|
@ -157,11 +183,11 @@
|
|||
address4 = mkAlmostOptionDefault "10.9.1.${toString index}/24";
|
||||
address6 = mkAlmostOptionDefault "fd0c::${UInt.toHexLower index}/64";
|
||||
macAddress = mkIf (system.proxmox.network.interfaces.net0.macAddress or null != null && hasPrefix "BC:24:11:" system.proxmox.network.interfaces.net0.macAddress) (mkAlmostOptionDefault (
|
||||
replaceStrings [ "BC:24:11:" ] [ "BC:24:19:" ] system.proxmox.network.interfaces.net0.macAddress
|
||||
replaceStrings ["BC:24:11:"] ["BC:24:19:"] system.proxmox.network.interfaces.net0.macAddress
|
||||
));
|
||||
networkd.name = mkDefault "_00-int";
|
||||
networkd.networkSettings = {
|
||||
domains = mkDefault [ ]; # int.${domain}?
|
||||
domains = mkDefault []; # int.${domain}?
|
||||
linkConfig.RequiredForOnline = false;
|
||||
ipv6AcceptRAConfig = {
|
||||
Token = mkOptionDefault "static:::${UInt.toHexLower index}";
|
||||
|
|
@ -172,21 +198,22 @@
|
|||
};
|
||||
};
|
||||
};
|
||||
in mkMerge [
|
||||
conf
|
||||
(mkIf config.internal.enable confInternal)
|
||||
];
|
||||
in
|
||||
mkMerge [
|
||||
conf
|
||||
(mkIf config.internal.enable confInternal)
|
||||
];
|
||||
};
|
||||
in {
|
||||
options.proxmox.network = with lib.types; {
|
||||
interfaces = mkOption {
|
||||
type = attrsOf (submoduleWith {
|
||||
modules = [ networkInterfaceModule ];
|
||||
modules = [networkInterfaceModule];
|
||||
specialArgs = {
|
||||
system = config;
|
||||
};
|
||||
});
|
||||
default = { };
|
||||
default = {};
|
||||
};
|
||||
internal = {
|
||||
interface = mkOption {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,9 @@
|
|||
{config, lib, gensokyo-zone, ...}: let
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
gensokyo-zone,
|
||||
...
|
||||
}: let
|
||||
inherit (gensokyo-zone.lib) mkAlmostOptionDefault;
|
||||
inherit (lib.options) mkOption mkEnableOption;
|
||||
inherit (lib.modules) mkIf;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
{config, lib, ...}: let
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib.options) mkOption mkEnableOption;
|
||||
cfg = config.proxmox;
|
||||
in {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue