345 lines
12 KiB
Nix
Raw Normal View History

2024-02-08 23:21:10 +03:00
{ config, pkgs, inputs, ... }:
2023-03-23 01:58:10 +03:00
let
2023-11-11 03:17:20 +03:00
authentik = { proxyPass ? null, proxyWebsockets ? false, root ? {}, rootExtraConfig ? "", locations ? {}, extraConfig ? "", ... }: {
extraConfig = ''
proxy_buffers 8 16k;
proxy_buffer_size 32k;
'' + extraConfig;
2023-03-23 01:58:10 +03:00
locations = locations // {
"/" = {
2023-11-11 03:17:20 +03:00
proxyPass = proxyPass;
proxyWebsockets = proxyWebsockets;
2023-03-23 01:58:10 +03:00
extraConfig = ''
auth_request /outpost.goauthentik.io/auth/nginx;
error_page 401 = @goauthentik_proxy_signin;
auth_request_set $auth_cookie $upstream_http_set_cookie;
add_header Set-Cookie $auth_cookie;
# translate headers from the outposts back to the actual upstream
auth_request_set $authentik_username $upstream_http_x_authentik_username;
auth_request_set $authentik_groups $upstream_http_x_authentik_groups;
auth_request_set $authentik_email $upstream_http_x_authentik_email;
auth_request_set $authentik_name $upstream_http_x_authentik_name;
auth_request_set $authentik_uid $upstream_http_x_authentik_uid;
2023-11-11 03:17:20 +03:00
auth_request_set $authentik_authorization $upstream_http_authorization;
2023-03-23 01:58:10 +03:00
proxy_set_header X-authentik-username $authentik_username;
proxy_set_header X-authentik-groups $authentik_groups;
proxy_set_header X-authentik-email $authentik_email;
proxy_set_header X-authentik-name $authentik_name;
proxy_set_header X-authentik-uid $authentik_uid;
2023-11-11 03:17:20 +03:00
proxy_set_header Authorization $authentik_authorization;
2023-03-23 01:58:10 +03:00
'' + rootExtraConfig;
} // root;
"/outpost.goauthentik.io" = {
extraConfig = ''
2023-11-11 03:17:20 +03:00
proxy_pass http://127.0.0.1:9000/outpost.goauthentik.io;
2023-03-23 01:58:10 +03:00
proxy_set_header Host $host;
proxy_set_header X-Original-URL $scheme://$http_host$request_uri;
add_header Set-Cookie $auth_cookie;
auth_request_set $auth_cookie $upstream_http_set_cookie;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
'';
};
"@goauthentik_proxy_signin" = {
extraConfig = ''
internal;
add_header Set-Cookie $auth_cookie;
2023-11-11 03:17:20 +03:00
return 302 /outpost.goauthentik.io/start?rd=$request_uri;
2023-03-23 01:58:10 +03:00
# For domain level, use the below error_page to redirect to your authentik server with the full redirect path
2023-11-11 03:17:20 +03:00
# return 302 https://auth.ataraxiadev.com/outpost.goauthentik.io/start?rd=$scheme://$http_host$request_uri;
2023-03-23 01:58:10 +03:00
'';
};
};
};
in {
2022-02-14 03:33:03 +03:00
services.nginx = {
enable = true;
group = "acme";
2023-10-13 19:51:59 +03:00
recommendedBrotliSettings = true;
2022-02-14 03:33:03 +03:00
recommendedGzipSettings = true;
2023-10-13 19:51:59 +03:00
recommendedOptimisation = true;
2022-02-14 03:33:03 +03:00
recommendedTlsSettings = true;
2023-10-13 19:51:59 +03:00
recommendedZstdSettings = true;
2022-03-22 06:02:13 +03:00
clientMaxBodySize = "250m";
2022-04-04 14:53:16 +03:00
commonHttpConfig = ''
proxy_hide_header X-Frame-Options;
'';
2022-02-14 03:33:03 +03:00
virtualHosts = let
default = {
useACMEHost = "ataraxiadev.com";
2022-03-22 06:01:10 +03:00
enableACME = false;
2022-02-14 03:33:03 +03:00
forceSSL = true;
};
2022-10-09 00:39:52 +03:00
proxySettings = ''
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
'';
hardened = ''
add_header Content-Security-Policy "frame-ancestors 'self' https://*.ataraxiadev.com";
add_header Referrer-Policy "strict-origin-when-cross-origin";
'';
2022-02-14 03:33:03 +03:00
in {
"ataraxiadev.com" = {
2022-11-20 19:14:20 +03:00
locations."/" = {
2023-04-25 17:24:01 +03:00
root = "/srv/http/ataraxiadev.com/docroot";
extraConfig = ''
try_files $uri $uri/ =404;
'';
};
2023-04-25 17:27:42 +03:00
locations."/hooks" = {
2024-01-21 16:29:00 +03:00
proxyPass = "http://127.0.0.1:9510/hooks";
2023-04-25 17:27:42 +03:00
};
2023-04-25 17:24:01 +03:00
locations."/.well-known/matrix" = {
proxyPass = "https://matrix.ataraxiadev.com/.well-known/matrix";
extraConfig = ''
proxy_set_header X-Forwarded-For $remote_addr;
'';
2022-11-20 19:14:20 +03:00
};
2022-02-14 03:33:03 +03:00
} // default;
2024-01-21 17:40:07 +03:00
"api.ataraxiadev.com" = {
2024-01-27 18:01:04 +03:00
locations."~ (\\.py)$" = with config.services; {
2024-01-21 17:40:07 +03:00
alias = "/srv/http/api.ataraxiadev.com";
extraConfig = ''
gzip off;
fastcgi_pass ${fcgiwrap.socketType}:${fcgiwrap.socketAddress};
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include ${pkgs.nginx}/conf/fastcgi_params;
'';
};
} // default;
"auth.ataraxiadev.com" = {
2023-07-26 21:20:52 +03:00
locations."/" = {
2024-01-21 17:40:07 +03:00
proxyPass = "http://127.0.0.1:9000";
2023-07-26 21:20:52 +03:00
proxyWebsockets = true;
2024-01-21 17:40:07 +03:00
extraConfig = proxySettings;
};
} // default;
"cache.ataraxiadev.com" = {
locations."/" = {
proxyPass = "http://127.0.0.1:8083";
2023-07-26 21:20:52 +03:00
extraConfig = ''
2024-01-21 17:40:07 +03:00
client_max_body_size 0;
send_timeout 15m;
2023-07-26 21:20:52 +03:00
'' + proxySettings;
};
} // default;
2023-07-30 03:30:49 +03:00
"cal.ataraxiadev.com" = {
locations."/" = {
proxyPass = "http://127.0.0.1:5232";
extraConfig = proxySettings;
};
} // default;
2024-01-21 17:40:07 +03:00
"code.ataraxiadev.com" = {
2022-02-21 02:25:13 +03:00
locations."/" = {
2024-01-21 17:40:07 +03:00
proxyPass = "http://127.0.0.1:6000";
2022-10-09 00:39:52 +03:00
extraConfig = proxySettings;
};
2022-02-21 02:25:13 +03:00
} // default;
2024-01-21 17:40:07 +03:00
"docs.ataraxiadev.com" = {
2022-03-10 19:12:07 +03:00
locations."/" = {
2024-01-21 17:40:07 +03:00
proxyPass = "http://127.0.0.1:3010";
proxyWebsockets = true;
extraConfig = ''
client_max_body_size 100M;
'' + proxySettings;
2022-10-09 00:39:52 +03:00
};
2022-03-10 19:12:07 +03:00
} // default;
2023-03-23 01:58:10 +03:00
"file.ataraxiadev.com" = {
locations."/" = {
2024-01-21 16:30:50 +03:00
proxyPass = "http://127.0.0.1:9200";
2023-03-23 01:58:10 +03:00
extraConfig = ''
2024-01-21 16:30:50 +03:00
proxy_set_header Host $host;
proxy_buffers 4 256k;
proxy_buffer_size 128k;
proxy_busy_buffers_size 256k;
# Disable checking of client request body size
2023-03-23 01:58:10 +03:00
client_max_body_size 0;
2023-12-18 02:08:29 +03:00
'';
2023-03-23 01:58:10 +03:00
};
} // default;
2024-01-21 17:40:07 +03:00
"home.ataraxiadev.com" = default // authentik {
proxyPass = "http://127.0.0.1:3000";
};
"joplin.ataraxiadev.com" = {
2023-03-23 01:58:10 +03:00
locations."/" = {
2024-01-21 17:40:07 +03:00
proxyPass = "http://127.0.0.1:22300";
2023-03-23 01:58:10 +03:00
extraConfig = proxySettings;
};
} // default;
2024-01-21 17:40:07 +03:00
"ldap.ataraxiadev.com" = default;
2023-12-30 04:42:09 +03:00
"lib.ataraxiadev.com" = default // authentik {
proxyPass = "http://127.0.0.1:8072";
2024-01-13 00:02:17 +03:00
proxyWebsockets = true;
2023-12-30 04:42:09 +03:00
};
2023-03-23 01:58:10 +03:00
"media-stack" = {
serverAliases = [
"jellyfin.ataraxiadev.com"
"qbit.ataraxiadev.com"
"prowlarr.ataraxiadev.com"
"jackett.ataraxiadev.com"
"sonarr.ataraxiadev.com"
"radarr.ataraxiadev.com"
"lidarr.ataraxiadev.com"
"kavita.ataraxiadev.com"
];
locations."/" = {
2023-04-08 18:17:14 +03:00
proxyPass = "http://127.0.0.1:8180";
2023-03-23 01:58:10 +03:00
proxyWebsockets = true;
extraConfig = ''
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
send_timeout 15m;
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 15m;
'' + proxySettings;
};
} // default;
2024-01-21 17:40:07 +03:00
"medusa.ataraxiadev.com" = {
2023-01-26 00:43:11 +03:00
locations."/" = {
2024-01-21 17:40:07 +03:00
proxyPass = "http://127.0.0.1:8180";
proxyWebsockets = true;
extraConfig = ''
add_header Content-Security-Policy "upgrade-insecure-requests";
'' + proxySettings;
2023-01-26 00:43:11 +03:00
};
} // default;
2024-01-21 17:40:07 +03:00
"openbooks.ataraxiadev.com" = default // authentik {
proxyPass = "http://127.0.0.1:8097";
proxyWebsockets = true;
};
"pdf.ataraxiadev.com" = default // authentik {
proxyPass = "http://127.0.0.1:8071";
};
2024-01-21 16:26:48 +03:00
"s3.ataraxiadev.com" = {
locations."/" = {
proxyPass = "http://127.0.0.1:9600";
extraConfig = ''
proxy_connect_timeout 300;
proxy_http_version 1.1;
proxy_set_header Connection "";
chunked_transfer_encoding off;
'' + proxySettings;
};
locations."/ui/" = {
proxyPass = "http://127.0.0.1:9601";
extraConfig = ''
rewrite ^/ui/(.*) /$1 break;
proxy_set_header X-NginX-Proxy true;
real_ip_header X-Real-IP;
proxy_connect_timeout 300;
chunked_transfer_encoding off;
'' + proxySettings;
proxyWebsockets = true;
};
extraConfig = ''
ignore_invalid_headers off;
client_max_body_size 0;
proxy_buffering off;
proxy_request_buffering off;
'';
} // default;
2024-02-15 21:36:15 +03:00
"stats.ataraxiadev.com" = {
locations."/" = {
proxyPass = "http://127.0.0.1:9002";
extraConfig = proxySettings;
};
locations."/api/live/" = {
proxyPass = "http://127.0.0.1:9002";
proxyWebsockets = true;
extraConfig = proxySettings;
};
} // default;
2024-01-21 17:40:07 +03:00
"tools.ataraxiadev.com" = default // authentik {
proxyPass = "http://127.0.0.1:8070";
};
2024-01-25 21:03:48 +03:00
"vault.ataraxiadev.com" = {
locations."/" = {
proxyPass = "http://127.0.0.1:8200";
extraConfig = proxySettings;
};
} // default;
2024-01-21 17:40:07 +03:00
"vw.ataraxiadev.com" = {
2023-10-13 19:51:59 +03:00
locations."/" = {
2024-01-21 17:40:07 +03:00
proxyPass = "http://127.0.0.1:8812";
extraConfig = proxySettings;
};
locations."/notifications/hub" = {
proxyPass = "http://127.0.0.1:3012";
2023-10-13 19:51:59 +03:00
proxyWebsockets = true;
extraConfig = proxySettings;
};
2024-01-21 17:40:07 +03:00
locations."/notifications/hub/negotiate" = {
proxyPass = "http://127.0.0.1:8812";
extraConfig = proxySettings;
};
2023-10-13 19:51:59 +03:00
} // default;
"wg.ataraxiadev.com" = {
2024-01-25 20:59:39 +03:00
locations."/headscale." = {
extraConfig = ''
grpc_pass grpc://${config.services.headscale.settings.grpc_listen_addr};
'';
priority = 1;
};
locations."/metrics" = {
proxyPass = "http://127.0.0.1:${toString config.services.headscale.port}";
extraConfig = ''
allow 100.64.0.0/16;
allow 192.168.0.0/24;
deny all;
'';
priority = 2;
};
2023-10-13 19:51:59 +03:00
locations."/" = {
proxyPass = "http://127.0.0.1:${toString config.services.headscale.port}";
proxyWebsockets = true;
2024-01-25 20:59:39 +03:00
priority = 3;
2023-10-13 19:51:59 +03:00
};
} // default;
2023-11-11 03:17:20 +03:00
"wiki.ataraxiadev.com" = default // authentik {
proxyPass = "http://127.0.0.1:8190";
};
2024-02-06 20:22:54 +03:00
"wopi.ataraxiadev.com" = default // {
locations."/" = {
proxyPass = "http://127.0.0.1:8880";
};
};
2022-02-14 03:33:03 +03:00
};
};
2024-01-21 17:40:07 +03:00
services.fcgiwrap = {
enable = true;
user = config.services.nginx.user;
group = config.services.nginx.group;
};
2024-01-22 16:44:51 +03:00
sops.secrets.narodmon-key.sopsFile = inputs.self.secretsDir + /home-hypervisor/api.yaml;
sops.secrets.narodmon-key.owner = config.services.nginx.user;
2024-01-27 18:01:04 +03:00
# Avoid api key revoke
systemd.services.narodmon-api = {
serviceConfig = {
Type = "oneshot";
User = config.services.nginx.user;
ExecStart = "${pkgs.narodmon-py}/bin/temp.py";
};
startAt = "daily";
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
};
2022-05-18 01:23:15 +03:00
2022-12-07 02:27:22 +03:00
system.activationScripts.linkPyScripts.text = ''
2023-01-13 04:03:15 +03:00
[ ! -d "/srv/http/api.ataraxiadev.com" ] && mkdir -p /srv/http/api.ataraxiadev.com
2022-12-07 02:27:22 +03:00
ln -sfn ${pkgs.narodmon-py}/bin/temp.py /srv/http/api.ataraxiadev.com/temp.py
'';
2022-08-05 21:03:54 +03:00
2024-01-21 17:40:07 +03:00
networking.firewall.allowedTCPPorts = [ 80 443 ];
2022-05-18 01:23:15 +03:00
}