refactor: Introduce interface types for network configuration

This commit is contained in:
Giulio De Pasquale (aider) 2025-04-26 16:57:07 +01:00
parent 08ae792712
commit 88990545ed
13 changed files with 54 additions and 33 deletions

View File

@ -6,6 +6,26 @@ let
in in
{ {
options.pepe.core.network = { options.pepe.core.network = {
interfaceTypes = {
lan = mkOption {
type = types.str;
default = "lan";
description = "Key for LAN interface";
};
wan = mkOption {
type = types.str;
default = "wan";
description = "Key for WAN interface";
};
vpn = mkOption {
type = types.str;
default = "tailscale";
description = "Key for VPN interface";
};
};
interfaces = mkOption { interfaces = mkOption {
type = types.attrsOf (types.submodule { type = types.attrsOf (types.submodule {
options = { options = {

View File

@ -13,6 +13,7 @@ in
type = types.listOf types.str; type = types.listOf types.str;
default = [ ]; default = [ ];
description = "List of interfaces to add extra DNS hosts for this vhost."; description = "List of interfaces to add extra DNS hosts for this vhost.";
example = "config.pepe.core.network.interfaceTypes.lan";
}; };
locations = mkOption { locations = mkOption {
@ -91,7 +92,7 @@ in
recommendedProxySettings = location.recommendedProxySettings; recommendedProxySettings = location.recommendedProxySettings;
extraConfig = '' extraConfig = ''
${concatMapStringsSep "\n" (allowCIDR: "allow ${allowCIDR};") location.allow} ${concatMapStringsSep "\n" (allowCIDR: "allow ${allowCIDR};") location.allow}
${optionalString location.allowLan ''allow ${config.pepe.core.network.interfaces."lan".net};''} ${optionalString location.allowLan ''allow ${config.pepe.core.network.interfaces.${config.pepe.core.network.interfaceTypes.lan}.net};''}
${optionalString (!location.allowWAN) "deny all;"} ${optionalString (!location.allowWAN) "deny all;"}
'' + location.extraConfig; '' + location.extraConfig;
}) })

View File

@ -22,13 +22,13 @@ in
group = "media"; group = "media";
}; };
pepe.core.vhost.hosts.${cfg.domain} = with config.pepe.core.network.interfaces; { pepe.core.vhost.hosts.${cfg.domain} = with config.pepe.core.network; {
dnsInterfaces = [ "tailscale" ]; dnsInterfaces = [ interfaceTypes.vpn ];
locations."/" = { locations."/" = {
port = 6767; port = 6767;
allowLan = true; allowLan = true;
allow = [ allow = [
tailscale.net interfaces.${interfaceTypes.vpn}.net
]; ];
}; };
}; };

View File

@ -18,8 +18,8 @@ in
config = mkIf cfg.enable { config = mkIf cfg.enable {
pepe.core = { pepe.core = {
firewall.openTCP = [ config.services.gitea.settings.server.SSH_PORT ]; firewall.openTCP = [ config.services.gitea.settings.server.SSH_PORT ];
vhost.hosts.${cfg.domain} = { vhost.hosts.${cfg.domain} = with config.pepe.core.network; {
dnsInterfaces = [ "lan" "tailscale" ]; dnsInterfaces = [ interfaceTypes.lan interfaceTypes.vpn ];
locations."/" = { locations."/" = {
port = config.services.gitea.settings.server.HTTP_PORT; port = config.services.gitea.settings.server.HTTP_PORT;
allowWAN = true; allowWAN = true;

View File

@ -22,14 +22,14 @@ in
}; };
}; };
pepe.core.vhost.hosts.${cfg.domain} = { pepe.core.vhost.hosts.${cfg.domain} = with config.pepe.core.network; {
dnsInterfaces = [ "tailscale" "lan" ]; dnsInterfaces = [ interfaceTypes.vpn interfaceTypes.lan ];
locations."/" = { locations."/" = {
host = "[::1]"; host = "[::1]";
port = config.services.immich.port; port = config.services.immich.port;
allowLan = true; allowLan = true;
allowWAN = true; allowWAN = true;
allow = [ config.pepe.core.network.interfaces."tailscale".net ]; allow = [ interfaces.${interfaceTypes.vpn}.net ];
proxyWebsockets = true; proxyWebsockets = true;
extraConfig = '' extraConfig = ''
# allow large file uploads # allow large file uploads

View File

@ -24,14 +24,14 @@ in
# needed since StateDirectory does not accept symlinks # needed since StateDirectory does not accept symlinks
systemd.services.jellyfin.serviceConfig.StateDirectory = mkForce ""; systemd.services.jellyfin.serviceConfig.StateDirectory = mkForce "";
pepe.core.vhost.hosts.${cfg.domain} = with config.pepe.core.network.interfaces; { pepe.core.vhost.hosts.${cfg.domain} = with config.pepe.core.network; {
dnsInterfaces = [ "lan" "tailscale" ]; dnsInterfaces = [ interfaceTypes.lan interfaceTypes.vpn ];
locations = { locations = {
"/" = { "/" = {
port = 8096; port = 8096;
allowLan = true; allowLan = true;
allow = [ allow = [
tailscale.net interfaces.${interfaceTypes.vpn}.net
]; ];
}; };
@ -40,7 +40,7 @@ in
allowLan = true; allowLan = true;
proxyWebsockets = true; proxyWebsockets = true;
allow = [ allow = [
tailscale.net interfaces.${interfaceTypes.vpn}.net
]; ];
}; };
}; };

View File

@ -21,13 +21,13 @@ in
package = cfg.package; package = cfg.package;
}; };
pepe.core.vhost.hosts.${cfg.domain} = with config.pepe.core.network.interfaces; { pepe.core.vhost.hosts.${cfg.domain} = with config.pepe.core.network; {
dnsInterfaces = [ "tailscale" "lan" ]; dnsInterfaces = [ interfaceTypes.vpn interfaceTypes.lan ];
locations."/" = { locations."/" = {
port = config.services.jellyseerr.port; port = config.services.jellyseerr.port;
allowLan = true; allowLan = true;
allow = [ allow = [
tailscale.net interfaces.${interfaceTypes.vpn}.net
]; ];
}; };
}; };

View File

@ -22,13 +22,13 @@ in
group = "media"; group = "media";
}; };
pepe.core.vhost.hosts.${cfg.domain} = with config.pepe.core.network.interfaces; { pepe.core.vhost.hosts.${cfg.domain} = with config.pepe.core.network; {
dnsInterfaces = [ "lan" "tailscale" ]; dnsInterfaces = [ interfaceTypes.lan interfaceTypes.vpn ];
locations."/" = { locations."/" = {
port = 8686; port = 8686;
allowLan = true; allowLan = true;
allow = [ allow = [
tailscale.net interfaces.${interfaceTypes.vpn}.net
]; ];
}; };
}; };

View File

@ -46,8 +46,8 @@ in
} // cfg.settings; } // cfg.settings;
}; };
pepe.core.vhost.hosts.${cfg.domain} = { pepe.core.vhost.hosts.${cfg.domain} = with config.pepe.core.network; {
dnsInterfaces = [ "lan" "tailscale" ]; dnsInterfaces = [ interfaceTypes.lan interfaceTypes.vpn ];
locations."/" = { locations."/" = {
port = 4533; port = 4533;
allowLan = true; allowLan = true;

View File

@ -22,13 +22,13 @@ in
group = "media"; group = "media";
}; };
pepe.core.vhost.hosts.${cfg.domain} = with config.pepe.core.network.interfaces; { pepe.core.vhost.hosts.${cfg.domain} = with config.pepe.core.network; {
dnsInterfaces = [ "tailscale" "lan" ]; dnsInterfaces = [ interfaceTypes.vpn interfaceTypes.lan ];
locations."/" = { locations."/" = {
port = 6789; port = 6789;
allowLan = true; allowLan = true;
allow = [ allow = [
tailscale.net interfaces.${interfaceTypes.vpn}.net
]; ];
}; };
}; };

View File

@ -21,14 +21,14 @@ in
package = cfg.package; package = cfg.package;
}; };
pepe.core.vhost.hosts.${cfg.domain} = with config.pepe.core.network.interfaces; { pepe.core.vhost.hosts.${cfg.domain} = with config.pepe.core.network; {
dnsInterfaces = [ "tailscale" "lan" ]; dnsInterfaces = [ interfaceTypes.vpn interfaceTypes.lan ];
locations."/" = { locations."/" = {
port = 9696; port = 9696;
allowLan = true; allowLan = true;
proxyWebsockets = true; proxyWebsockets = true;
allow = [ allow = [
tailscale.net interfaces.${interfaceTypes.vpn}.net
]; ];
}; };
}; };

View File

@ -21,14 +21,14 @@ in
package = cfg.package; package = cfg.package;
}; };
pepe.core.vhost.hosts.${cfg.domain} = with config.pepe.core.network.interfaces; { pepe.core.vhost.hosts.${cfg.domain} = with config.pepe.core.network; {
dnsInterfaces = [ "tailscale" "lan" ]; dnsInterfaces = [ interfaceTypes.vpn interfaceTypes.lan ];
locations."/" = { locations."/" = {
port = 7878; port = 7878;
allowLan = true; allowLan = true;
allow = [ allow = [
tailscale.net interfaces.${interfaceTypes.vpn}.net
]; ];
}; };
}; };

View File

@ -21,13 +21,13 @@ in
package = cfg.package; package = cfg.package;
}; };
pepe.core.vhost.hosts.${cfg.domain} = with config.pepe.core.network.interfaces; { pepe.core.vhost.hosts.${cfg.domain} = with config.pepe.core.network; {
dnsInterfaces = [ "tailscale" "lan" ]; dnsInterfaces = [ interfaceTypes.vpn interfaceTypes.lan ];
locations."/" = { locations."/" = {
port = 8989; port = 8989;
allowLan = true; allowLan = true;
allow = [ allow = [
tailscale.net interfaces.${interfaceTypes.vpn}.net
]; ];
}; };
}; };