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
{
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 {
type = types.attrsOf (types.submodule {
options = {

View File

@ -13,6 +13,7 @@ in
type = types.listOf types.str;
default = [ ];
description = "List of interfaces to add extra DNS hosts for this vhost.";
example = "config.pepe.core.network.interfaceTypes.lan";
};
locations = mkOption {
@ -91,7 +92,7 @@ in
recommendedProxySettings = location.recommendedProxySettings;
extraConfig = ''
${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;"}
'' + location.extraConfig;
})

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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