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";
|
|
|
|
forgejo = "git";
|
|
|
|
immich = "immich";
|
|
|
|
nextcloud = "nc";
|
|
|
|
ollama = "ollama";
|
|
|
|
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-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
|
|
|
|
ipOf = hostName: 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-14 20:07:10 +01:00
|
|
|
in
|
2024-03-14 23:08:42 +01:00
|
|
|
lib.mkMerge [
|
|
|
|
{
|
|
|
|
enable = true;
|
|
|
|
recommendedSetup = true;
|
|
|
|
}
|
|
|
|
(blockOf "vaultwarden" {maxBodySize = "1G";})
|
|
|
|
(blockOf "forgejo" {maxBodySize = "1G";})
|
|
|
|
(blockOf "immich" {maxBodySize = "5G";})
|
2024-03-19 00:46:35 +01:00
|
|
|
(lib.mkMerge
|
|
|
|
[
|
|
|
|
(
|
|
|
|
blockOf "adguardhome"
|
|
|
|
{
|
|
|
|
}
|
|
|
|
)
|
|
|
|
{
|
|
|
|
virtualHosts.${domainOf "adguardhome"} = {
|
|
|
|
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
|
|
|
|
auth_request_set $user $upstream_http_x_auth_request_user;
|
|
|
|
auth_request_set $email $upstream_http_x_auth_request_email;
|
|
|
|
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" = {
|
|
|
|
proxyPass = "http://oauth2-proxy/oauth2/auth?allowed_groups=adguardhome_access";
|
|
|
|
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;
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
])
|
|
|
|
(lib.mkMerge [
|
|
|
|
(blockOf "oauth2-proxy" {})
|
2024-03-14 23:08:42 +01:00
|
|
|
{
|
2024-03-19 00:46:35 +01:00
|
|
|
virtualHosts.${domainOf "oauth2-proxy"} = {
|
|
|
|
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
|
|
|
|
auth_request_set $user $upstream_http_x_auth_request_user;
|
|
|
|
auth_request_set $email $upstream_http_x_auth_request_email;
|
|
|
|
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" = {
|
|
|
|
proxyPass = "http://oauth2-proxy/oauth2/auth";
|
|
|
|
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 23:08:42 +01:00
|
|
|
}
|
2024-03-19 00:46:35 +01:00
|
|
|
])
|
2024-03-14 23:08:42 +01:00
|
|
|
(blockOf "paperless" {maxBodySize = "5G";})
|
|
|
|
(blockOf "ttrss" {port = 80;})
|
|
|
|
(blockOf "yourspotify" {port = 80;})
|
|
|
|
(blockOf "apispotify" {
|
|
|
|
port = 80;
|
|
|
|
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 = [
|
|
|
|
../../modules/config
|
|
|
|
../../modules/services/${guestName}.nix
|
|
|
|
{
|
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
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
#deadnix: skip
|
|
|
|
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-01-26 01:04:08 +01:00
|
|
|
// mkContainer "ollama" {}
|
2024-02-13 18:07:45 +01:00
|
|
|
// mkContainer "ttrss" {}
|
2024-03-02 22:26:12 +01:00
|
|
|
// mkContainer "yourspotify" {}
|
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
|
|
|
};
|
|
|
|
}
|