2024-01-11 22:42:03 +01:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
stateVersion,
|
|
|
|
inputs,
|
|
|
|
lib,
|
|
|
|
minimal,
|
|
|
|
nodes,
|
|
|
|
...
|
|
|
|
}: let
|
2024-03-14 20:07:10 +01:00
|
|
|
domainOf = hostName: let
|
|
|
|
domains = {
|
|
|
|
adguardhome = "adguardhome";
|
2024-04-13 19:17:41 +02:00
|
|
|
forgejo = "forge";
|
2024-03-14 20:07:10 +01:00
|
|
|
immich = "immich";
|
|
|
|
nextcloud = "nc";
|
2024-06-09 20:59:23 +02:00
|
|
|
ollama = "ai";
|
2024-03-14 20:07:10 +01:00
|
|
|
paperless = "ppl";
|
|
|
|
ttrss = "rss";
|
|
|
|
vaultwarden = "pw";
|
2024-03-14 23:08:42 +01:00
|
|
|
yourspotify = "sptfy";
|
2024-03-14 20:07:10 +01:00
|
|
|
apispotify = "apisptfy";
|
|
|
|
kanidm = "auth";
|
2024-03-19 00:46:35 +01:00
|
|
|
oauth2-proxy = "oauth2";
|
2024-03-21 20:39:59 +01:00
|
|
|
netbird = "netbird";
|
2024-03-30 20:34:44 +01:00
|
|
|
actual = "actual";
|
2024-04-02 21:57:59 +02:00
|
|
|
firefly = "money";
|
2024-06-05 23:00:40 +02:00
|
|
|
homebox = "homebox";
|
2024-07-12 13:27:08 +02:00
|
|
|
octoprint = "print";
|
2024-07-19 07:01:37 +02:00
|
|
|
pr-tracker = "tracker";
|
2024-03-14 20:07:10 +01:00
|
|
|
};
|
|
|
|
in "${domains.${hostName}}.${config.secrets.secrets.global.domains.web}";
|
2024-03-14 23:08:42 +01:00
|
|
|
# TODO hard coded elisabeth nicht so schön
|
2024-07-12 13:27:08 +02:00
|
|
|
ipOf = hostName:
|
2024-07-13 01:04:40 +02:00
|
|
|
if nodes ? ${hostName}
|
2024-07-12 13:27:08 +02:00
|
|
|
then nodes.${hostName}.config.wireguard.elisabeth.ipv4
|
|
|
|
else nodes."elisabeth-${hostName}".config.wireguard.elisabeth.ipv4;
|
2024-01-11 22:42:03 +01:00
|
|
|
in {
|
2024-03-14 20:07:10 +01:00
|
|
|
services.nginx = let
|
|
|
|
blockOf = hostName: {
|
|
|
|
virtualHostExtraConfig ? "",
|
|
|
|
maxBodySize ? "500M",
|
|
|
|
port ? 3000,
|
2024-03-14 23:08:42 +01:00
|
|
|
upstream ? hostName,
|
|
|
|
protocol ? "http",
|
2024-03-14 20:07:10 +01:00
|
|
|
}: {
|
|
|
|
upstreams.${hostName} = {
|
2024-03-14 23:08:42 +01:00
|
|
|
servers."${ipOf upstream}:${toString port}" = {};
|
2024-03-14 20:07:10 +01:00
|
|
|
extraConfig = ''
|
|
|
|
zone ${hostName} 64k ;
|
|
|
|
keepalive 5 ;
|
|
|
|
'';
|
2024-01-12 15:47:43 +01:00
|
|
|
};
|
2024-03-14 20:07:10 +01:00
|
|
|
virtualHosts.${domainOf hostName} = {
|
|
|
|
forceSSL = true;
|
|
|
|
useACMEHost = "web";
|
|
|
|
locations."/" = {
|
2024-03-14 23:08:42 +01:00
|
|
|
proxyPass = "${protocol}://${hostName}";
|
2024-03-14 20:07:10 +01:00
|
|
|
proxyWebsockets = true;
|
|
|
|
X-Frame-Options = "SAMEORIGIN";
|
|
|
|
};
|
|
|
|
extraConfig =
|
|
|
|
''
|
|
|
|
client_max_body_size ${maxBodySize} ;
|
|
|
|
''
|
|
|
|
+ virtualHostExtraConfig;
|
2024-01-20 21:07:00 +01:00
|
|
|
};
|
|
|
|
};
|
2024-03-30 20:34:44 +01:00
|
|
|
proxyProtect = hostName: cfg: allowedGroup:
|
2024-03-30 16:29:00 +01:00
|
|
|
lib.mkMerge [
|
|
|
|
(blockOf hostName cfg)
|
|
|
|
{
|
|
|
|
virtualHosts.${domainOf hostName} = {
|
|
|
|
locations."/".extraConfig = ''
|
|
|
|
auth_request /oauth2/auth;
|
|
|
|
error_page 401 = /oauth2/sign_in;
|
|
|
|
|
|
|
|
# pass information via X-User and X-Email headers to backend,
|
|
|
|
# requires running with --set-xauthrequest flag
|
2024-05-24 22:03:14 +02:00
|
|
|
auth_request_set $user $upstream_http_x_auth_request_preferred_username;
|
2024-06-09 20:59:23 +02:00
|
|
|
# Set the email to our own domain in case user change their mail
|
|
|
|
auth_request_set $email "''${upstream_http_x_auth_request_preferred_username}@${config.secrets.secrets.global.domains.web}";
|
2024-03-30 16:29:00 +01:00
|
|
|
proxy_set_header X-User $user;
|
|
|
|
proxy_set_header X-Email $email;
|
|
|
|
|
|
|
|
# if you enabled --cookie-refresh, this is needed for it to work with auth_request
|
|
|
|
auth_request_set $auth_cookie $upstream_http_set_cookie;
|
|
|
|
add_header Set-Cookie $auth_cookie;
|
|
|
|
'';
|
|
|
|
locations."/oauth2/" = {
|
|
|
|
proxyPass = "http://oauth2-proxy";
|
|
|
|
extraConfig = ''
|
|
|
|
proxy_set_header X-Scheme $scheme;
|
|
|
|
proxy_set_header X-Auth-Request-Redirect $scheme://$host$request_uri;
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
locations."= /oauth2/auth" = {
|
2024-03-30 20:34:44 +01:00
|
|
|
proxyPass = "http://oauth2-proxy/oauth2/auth" + lib.optionalString allowedGroup "?allowed_groups=${hostName}_access";
|
2024-03-30 16:29:00 +01:00
|
|
|
extraConfig = ''
|
|
|
|
internal;
|
|
|
|
|
|
|
|
proxy_set_header X-Scheme $scheme;
|
|
|
|
# nginx auth_request includes headers but not body
|
|
|
|
proxy_set_header Content-Length "";
|
|
|
|
proxy_pass_request_body off;
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
2024-03-14 20:07:10 +01:00
|
|
|
in
|
2024-03-14 23:08:42 +01:00
|
|
|
lib.mkMerge [
|
|
|
|
{
|
|
|
|
enable = true;
|
|
|
|
recommendedSetup = true;
|
2024-03-21 20:39:59 +01:00
|
|
|
upstreams.netbird = {
|
|
|
|
servers."${ipOf "netbird"}:80" = {};
|
|
|
|
extraConfig = ''
|
|
|
|
zone netbird 64k ;
|
|
|
|
keepalive 5 ;
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
upstreams.netbird-mgmt = {
|
|
|
|
servers."${ipOf "netbird"}:3000" = {};
|
|
|
|
extraConfig = ''
|
|
|
|
zone netbird 64k ;
|
|
|
|
keepalive 5 ;
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
virtualHosts.${domainOf "netbird"} = {
|
|
|
|
forceSSL = true;
|
|
|
|
useACMEHost = "web";
|
|
|
|
locations = {
|
|
|
|
"/" = {
|
|
|
|
proxyPass = "http://netbird";
|
|
|
|
proxyWebsockets = true;
|
|
|
|
X-Frame-Options = "SAMEORIGIN";
|
|
|
|
};
|
|
|
|
"/signalexchange.SignalExchange/".extraConfig = ''
|
|
|
|
grpc_pass grpc://${ipOf "netbird"}:3001;
|
|
|
|
grpc_read_timeout 1d;
|
|
|
|
grpc_send_timeout 1d;
|
|
|
|
grpc_socket_keepalive on;
|
|
|
|
'';
|
|
|
|
|
|
|
|
"/api".proxyPass = "http://netbird-mgmt";
|
|
|
|
|
|
|
|
"/management.ManagementService/".extraConfig = ''
|
|
|
|
grpc_pass grpc://${ipOf "netbird"}:3000;
|
|
|
|
grpc_read_timeout 1d;
|
|
|
|
grpc_send_timeout 1d;
|
|
|
|
grpc_socket_keepalive on;
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
extraConfig = ''
|
|
|
|
client_max_body_size 500M ;
|
2024-03-24 21:06:11 +01:00
|
|
|
client_header_timeout 1d;
|
|
|
|
client_body_timeout 1d;
|
2024-03-21 20:39:59 +01:00
|
|
|
'';
|
|
|
|
};
|
2024-03-14 23:08:42 +01:00
|
|
|
}
|
|
|
|
(blockOf "vaultwarden" {maxBodySize = "1G";})
|
|
|
|
(blockOf "forgejo" {maxBodySize = "1G";})
|
|
|
|
(blockOf "immich" {maxBodySize = "5G";})
|
2024-03-30 20:34:44 +01:00
|
|
|
(proxyProtect "adguardhome" {} true)
|
|
|
|
(proxyProtect "oauth2-proxy" {} false)
|
2024-03-14 23:08:42 +01:00
|
|
|
(blockOf "paperless" {maxBodySize = "5G";})
|
2024-03-30 20:34:44 +01:00
|
|
|
(proxyProtect "ttrss" {port = 80;} true)
|
2024-03-14 23:08:42 +01:00
|
|
|
(blockOf "yourspotify" {port = 80;})
|
2024-07-07 01:49:16 +02:00
|
|
|
#(blockOf "homebox" {})
|
2024-07-19 07:01:37 +02:00
|
|
|
(blockOf "pr-tracker" {})
|
|
|
|
{
|
|
|
|
virtualHosts.${domainOf "pr-tracker"} = {
|
|
|
|
locations."/update" = {
|
|
|
|
deny = "all";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
2024-07-07 01:49:16 +02:00
|
|
|
(proxyProtect "ollama" {} true)
|
2024-07-12 13:27:08 +02:00
|
|
|
(proxyProtect "octoprint" {} true)
|
2024-06-09 20:59:23 +02:00
|
|
|
(proxyProtect "firefly" {port = 80;} true)
|
2024-03-14 23:08:42 +01:00
|
|
|
(blockOf "apispotify" {
|
2024-03-27 17:05:20 +01:00
|
|
|
port = 3000;
|
2024-03-14 23:08:42 +01:00
|
|
|
upstream = "yourspotify";
|
|
|
|
})
|
|
|
|
(blockOf "nextcloud" {
|
|
|
|
maxBodySize = "5G";
|
|
|
|
port = 80;
|
|
|
|
})
|
|
|
|
(blockOf "kanidm"
|
|
|
|
{
|
|
|
|
protocol = "https";
|
|
|
|
virtualHostExtraConfig = ''
|
|
|
|
proxy_ssl_verify off ;
|
|
|
|
'';
|
|
|
|
})
|
|
|
|
];
|
2024-03-14 20:07:10 +01:00
|
|
|
|
2024-01-11 22:42:03 +01:00
|
|
|
guests = let
|
|
|
|
mkGuest = guestName: {
|
|
|
|
enablePanzer ? false,
|
|
|
|
enableRenaultFT ? false,
|
2024-01-15 02:13:46 +01:00
|
|
|
enableBunker ? false,
|
2024-01-18 00:39:25 +01:00
|
|
|
enableSharedPaperless ? false,
|
2024-01-11 22:42:03 +01:00
|
|
|
...
|
|
|
|
}: {
|
|
|
|
autostart = true;
|
|
|
|
zfs."/state" = {
|
|
|
|
pool = "rpool";
|
|
|
|
dataset = "local/guests/${guestName}";
|
|
|
|
};
|
|
|
|
zfs."/persist" = {
|
|
|
|
pool = "rpool";
|
|
|
|
dataset = "safe/guests/${guestName}";
|
|
|
|
};
|
|
|
|
zfs."/panzer" = lib.mkIf enablePanzer {
|
|
|
|
pool = "panzer";
|
|
|
|
dataset = "safe/guests/${guestName}";
|
|
|
|
};
|
|
|
|
zfs."/renaultft" = lib.mkIf enableRenaultFT {
|
|
|
|
pool = "renaultft";
|
|
|
|
dataset = "safe/guests/${guestName}";
|
|
|
|
};
|
2024-03-14 20:07:10 +01:00
|
|
|
# kinda not necesarry should be removed on next reimaging
|
2024-01-15 02:13:46 +01:00
|
|
|
zfs."/bunker" = lib.mkIf enableBunker {
|
|
|
|
pool = "panzer";
|
|
|
|
dataset = "bunker/guests/${guestName}";
|
|
|
|
};
|
2024-01-18 00:39:25 +01:00
|
|
|
zfs."/paperless" = lib.mkIf enableSharedPaperless {
|
|
|
|
pool = "panzer";
|
|
|
|
dataset = "bunker/shared/paperless";
|
|
|
|
};
|
2024-01-11 22:42:03 +01:00
|
|
|
modules = [
|
2024-04-11 23:11:53 +02:00
|
|
|
../../config/basic
|
|
|
|
../../config/services/${guestName}.nix
|
2024-01-11 22:42:03 +01:00
|
|
|
{
|
2024-03-05 00:34:50 +01:00
|
|
|
node.secretsDir = config.node.secretsDir + "/${guestName}";
|
2024-03-14 23:08:42 +01:00
|
|
|
networking.nftables.firewall.zones.untrusted.interfaces = [config.guests.${guestName}.networking.mainLinkName];
|
2024-01-11 22:42:03 +01:00
|
|
|
systemd.network.networks."10-${config.guests.${guestName}.networking.mainLinkName}" = {
|
|
|
|
DHCP = lib.mkForce "no";
|
2024-01-13 16:07:55 +01:00
|
|
|
address = [
|
2024-02-10 17:53:16 +01:00
|
|
|
(lib.net.cidr.hostCidr config.secrets.secrets.global.net.ips."${config.guests.${guestName}.nodeName}" config.secrets.secrets.global.net.privateSubnetv4)
|
|
|
|
(lib.net.cidr.hostCidr config.secrets.secrets.global.net.ips."${config.guests.${guestName}.nodeName}" config.secrets.secrets.global.net.privateSubnetv6)
|
2024-01-13 16:07:55 +01:00
|
|
|
];
|
2024-02-10 17:53:16 +01:00
|
|
|
gateway = [(lib.net.cidr.host 1 config.secrets.secrets.global.net.privateSubnetv4)];
|
2024-01-11 22:42:03 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
mkMicrovm = guestName: cfg: {
|
|
|
|
${guestName} =
|
|
|
|
mkGuest guestName cfg
|
|
|
|
// {
|
|
|
|
backend = "microvm";
|
|
|
|
microvm = {
|
|
|
|
system = "x86_64-linux";
|
|
|
|
macvtap = "lan";
|
2024-01-21 00:43:50 +01:00
|
|
|
baseMac = config.secrets.secrets.local.networking.interfaces.lan01.mac;
|
2024-01-11 22:42:03 +01:00
|
|
|
};
|
|
|
|
extraSpecialArgs = {
|
|
|
|
inherit (inputs.self) nodes;
|
|
|
|
inherit (inputs.self.pkgs.x86_64-linux) lib;
|
|
|
|
inherit inputs minimal stateVersion;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
mkContainer = guestName: cfg: {
|
|
|
|
${guestName} =
|
|
|
|
mkGuest guestName cfg
|
|
|
|
// {
|
|
|
|
backend = "container";
|
|
|
|
container.macvlan = "lan";
|
|
|
|
extraSpecialArgs = {
|
|
|
|
inherit lib nodes inputs minimal stateVersion;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{}
|
|
|
|
// mkContainer "adguardhome" {}
|
2024-03-19 00:46:35 +01:00
|
|
|
// mkContainer "oauth2-proxy" {}
|
2024-01-12 17:16:37 +01:00
|
|
|
// mkContainer "vaultwarden" {}
|
2024-01-13 19:23:51 +01:00
|
|
|
// mkContainer "ddclient" {}
|
2024-07-07 01:49:16 +02:00
|
|
|
// mkContainer "ollama" {}
|
2024-03-27 18:18:24 +01:00
|
|
|
// mkContainer "murmur" {}
|
2024-07-07 01:49:16 +02:00
|
|
|
#// mkContainer "homebox" {}
|
2024-07-19 07:01:37 +02:00
|
|
|
// mkContainer "pr-tracker" {}
|
2024-03-27 17:05:20 +01:00
|
|
|
// mkContainer "ttrss" {}
|
2024-04-02 21:57:59 +02:00
|
|
|
// mkContainer "firefly" {}
|
2024-03-02 22:26:12 +01:00
|
|
|
// mkContainer "yourspotify" {}
|
2024-03-21 20:39:59 +01:00
|
|
|
// mkContainer "netbird" {}
|
2024-03-05 00:34:50 +01:00
|
|
|
// mkContainer "kanidm" {}
|
2024-01-11 22:42:03 +01:00
|
|
|
// mkContainer "nextcloud" {
|
|
|
|
enablePanzer = true;
|
|
|
|
}
|
2024-01-18 00:39:25 +01:00
|
|
|
// mkContainer "paperless" {
|
|
|
|
enableSharedPaperless = true;
|
|
|
|
}
|
2024-03-12 18:19:52 +01:00
|
|
|
// mkContainer "forgejo" {
|
2024-01-12 15:47:43 +01:00
|
|
|
enablePanzer = true;
|
|
|
|
}
|
2024-01-21 00:43:50 +01:00
|
|
|
// mkMicrovm "immich" {
|
2024-01-20 21:07:00 +01:00
|
|
|
enablePanzer = true;
|
|
|
|
}
|
2024-01-11 22:42:03 +01:00
|
|
|
// mkContainer "samba" {
|
|
|
|
enablePanzer = true;
|
|
|
|
enableRenaultFT = true;
|
2024-01-18 00:39:25 +01:00
|
|
|
enableBunker = true;
|
|
|
|
enableSharedPaperless = true;
|
2024-01-11 22:42:03 +01:00
|
|
|
};
|
|
|
|
}
|