refactor: network-services now use updated configuration format instead of old

This commit is contained in:
Ceferino Patino 2026-05-15 18:55:29 -05:00
commit 6bb617962a
Signed by: c4patino
SSH key fingerprint: SHA256:Wu+cU1t+7zVT9wzew/4meNmeulo66NzMqc22MdDBgXI
5 changed files with 68 additions and 58 deletions

View file

@ -73,9 +73,6 @@ in {
port = 5201;
public = true;
};
blocky = {
port = 53;
};
};
shiori = {
@ -103,10 +100,15 @@ in {
port = 5301;
internal = true;
};
blocky = {
port = 53;
};
unbound = {
port = 54;
};
};
};
unbound.dnsHost = "shiori";
};
};
}

View file

@ -5,19 +5,17 @@
pkgs,
...
}: let
inherit (lib) mkIf mkEnableOption mapAttrsToList listToAttrs;
inherit (lib.${namespace}) getAttrByNamespace mkOptionsWithNamespace resolveHostIP;
base = "${namespace}.services.networking.blocky";
cfg = getAttrByNamespace config base;
inherit (lib) mkIf mapAttrsToList listToAttrs;
inherit (lib.${namespace}) getAttrByNamespace resolveHostIP flattenHostServices hostHasServices getServicePort;
inherit (config.networking) hostName;
networkCfg = getAttrByNamespace config "${namespace}.services.networking";
networkServices = flattenHostServices networkCfg.network-services;
port = 53;
isEnabled = hostHasServices networkCfg.network-services hostName;
port = getServicePort networkServices "blocky" 53;
in {
options = mkOptionsWithNamespace base {
enable = mkEnableOption "blocky";
};
config = mkIf cfg.enable {
config = mkIf isEnabled {
services.blocky = {
enable = true;
settings = {
@ -110,7 +108,7 @@ in {
customDNS = {
customTTL = "1h";
mapping =
networkCfg.network-services
networkServices
|> mapAttrsToList (name: svc: {
name = "${name}.yumeami.sh";
value = resolveHostIP networkCfg.devices svc.host;

View file

@ -6,13 +6,17 @@
...
}: let
inherit (lib) mkIf mkEnableOption mapAttrsToList listToAttrs replaceStrings mkMerge concatStringsSep filterAttrs;
inherit (lib.${namespace}) getAttrByNamespace mkOptionsWithNamespace readJsonOrEmpty getIn resolveHostIP;
inherit (lib.${namespace}) getAttrByNamespace mkOptionsWithNamespace readJsonOrEmpty getIn resolveHostIP flattenHostServices;
inherit (config.networking) hostName;
base = "${namespace}.services.networking.httpd";
cfg = getAttrByNamespace config base;
networkingCfg = getAttrByNamespace config "${namespace}.services.networking";
miasmaCfg = getAttrByNamespace config "${namespace}.services.networking.miasma";
networkServices = networkingCfg.network-services;
networkServicesFlat = flattenHostServices networkServices;
crypt = "${inputs.self}/secrets/crypt";
mkLocalhostConfig = name: service: let
@ -28,13 +32,11 @@
domain,
useSSL,
injectHoneypot ? false,
}: name: service: let
}: host: name: service: let
inherit (config.sops) secrets;
host = resolveHostIP networkingCfg.devices service.host;
hostIP = resolveHostIP networkingCfg.devices host;
p = toString service.port;
miasma = networkingCfg.network-services.miasma;
certs = replaceStrings ["*" "."] ["wildcard" "_"] domain;
sslConfig =
if useSSL
@ -45,6 +47,8 @@
}
else {};
miasma = networkServicesFlat.miasma;
honeypotConfig =
if injectHoneypot
then ''
@ -88,8 +92,8 @@
${robotsConfig}
# --- ${name} (subdomain access) ---
ProxyPass / http://${host}:${p}/
ProxyPassReverse / http://${host}:${p}/
ProxyPass / http://${hostIP}:${p}/
ProxyPassReverse / http://${hostIP}:${p}/
'';
}
// sslConfig;
@ -169,7 +173,7 @@ in {
{
"localhost" = let
localhostProxyConfig =
networkingCfg.network-services
networkServices.${hostName}
|> mapAttrsToList mkLocalhostConfig
|> concatStringsSep "\n";
in {
@ -195,22 +199,32 @@ in {
};
}
(networkingCfg.network-services
|> filterAttrs (_: svc: svc.host == hostName && svc.internal)
|> mapAttrsToList (mkVirtualHost {
domain = "*.yumeami.sh";
useSSL = true;
})
(networkServices.${hostName}
|> filterAttrs (_: svc: svc.internal)
|> mapAttrsToList (name: svc:
(mkVirtualHost {
domain = "*.yumeami.sh";
useSSL = true;
})
hostName
name
svc)
|> listToAttrs)
(mkIf networkingCfg.cloudflared.enable (networkingCfg.network-services
(mkIf networkingCfg.cloudflared.enable (
networkServicesFlat
|> filterAttrs (_: svc: svc.public)
|> mapAttrsToList (mkVirtualHost {
domain = "*.cpatino.com";
useSSL = false;
injectHoneypot = true;
})
|> listToAttrs))
|> mapAttrsToList (name: svc:
(mkVirtualHost {
domain = "*.cpatino.com";
useSSL = false;
injectHoneypot = true;
})
svc.host
name
svc)
|> listToAttrs
))
];
};

View file

@ -5,17 +5,20 @@
pkgs,
...
}: let
inherit (lib) mkIf mkEnableOption mkOption types;
inherit (lib.${namespace}) getAttrByNamespace mkOptionsWithNamespace;
inherit (lib) mkIf mkOption types;
inherit (lib.${namespace}) getAttrByNamespace mkOptionsWithNamespace hostHasServices flattenHostServices getServicePort;
inherit (config.networking) hostName;
base = "${namespace}.services.networking.miasma";
cfg = getAttrByNamespace config base;
networkCfg = getAttrByNamespace config "${namespace}.services.networking";
networkServices = flattenHostServices networkCfg.network-services;
port = 9999;
isEnabled = hostHasServices networkCfg.network-services hostName;
port = getServicePort networkServices "miasma" 9999;
in {
options = with types;
mkOptionsWithNamespace base {
enable = mkEnableOption "miasma";
host = mkOption {
type = str;
default = "0.0.0.0";
@ -28,7 +31,7 @@ in {
};
};
config = mkIf cfg.enable {
config = mkIf isEnabled {
systemd.services.miasma = {
description = "Trap AI web scrapers in an endless poison pit";
wantedBy = ["multi-user.target"];

View file

@ -4,24 +4,17 @@
namespace,
...
}: let
inherit (lib) types mkIf mkEnableOption mkOption;
inherit (lib.${namespace}) getAttrByNamespace mkOptionsWithNamespace;
base = "${namespace}.services.networking.unbound";
cfg = getAttrByNamespace config base;
inherit (lib) mkIf;
inherit (lib.${namespace}) getAttrByNamespace hostHasServices flattenHostServices getServicePort;
inherit (config.networking) hostName;
port = 54;
networkCfg = getAttrByNamespace config "${namespace}.services.networking";
networkServices = flattenHostServices networkCfg.network-services;
isEnabled = hostHasServices networkCfg.network-services hostName;
port = getServicePort networkServices "unbound" 54;
in {
options = with types;
mkOptionsWithNamespace base {
enable = mkEnableOption "unbound";
dnsHost = mkOption {
type = nullOr str;
description = "Hostname target for other devices will reach out to as a DNS server.";
default = null;
};
};
config = mkIf cfg.enable {
config = mkIf isEnabled {
services.unbound = {
enable = true;
settings = {