365 lines
12 KiB
Nix
Raw Normal View History

2023-03-23 01:58:10 +03:00
{ config, lib, pkgs, ... }:
let
authentik = { root ? {}, rootExtraConfig ? "", locations ? {}, ... }: {
locations = locations // {
"/" = {
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;
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;
'' + rootExtraConfig;
} // root;
# all requests to /outpost.goauthentik.io must be accessible without authentication
"/outpost.goauthentik.io" = {
extraConfig = ''
proxy_pass http://127.0.0.1:9000/outpost.goauthentik.io;
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 "";
'';
};
# Special location for when the /auth endpoint returns a 401, redirect to the /start URL which initiates SSO
"@goauthentik_proxy_signin" = {
extraConfig = ''
internal;
add_header Set-Cookie $auth_cookie;
# return 302 /outpost.goauthentik.io/start?rd=$request_uri;
# For domain level, use the below error_page to redirect to your authentik server with the full redirect path
return 302 https://auth.ataraxiadev.com/outpost.goauthentik.io/start?rd=$scheme://$http_host$request_uri;
'';
};
};
};
in {
2023-01-13 04:03:15 +03:00
security.acme.certs = {
"ataraxiadev.com" = {
webroot = "/var/lib/acme/acme-challenge";
extraDomainNames = [
"startpage.ataraxiadev.com"
"vw.ataraxiadev.com"
"code.ataraxiadev.com"
2023-03-23 01:58:10 +03:00
"fb.ataraxiadev.com"
"browser.ataraxiadev.com"
2023-01-13 04:03:15 +03:00
"webmail.ataraxiadev.com"
2023-03-23 01:58:10 +03:00
"jellyfin.ataraxiadev.com"
"medusa.ataraxiadev.com"
"qbit.ataraxiadev.com"
"jackett.ataraxiadev.com"
"ldap.ataraxiadev.com"
2023-01-26 00:43:11 +03:00
"bathist.ataraxiadev.com"
"joplin.ataraxiadev.com"
2023-01-13 04:03:15 +03:00
"api.ataraxiadev.com"
2023-01-26 00:43:11 +03:00
"fsync.ataraxiadev.com"
2023-01-26 04:45:14 +03:00
"auth.ataraxiadev.com"
2023-03-23 01:58:10 +03:00
"sonarr.ataraxiadev.com"
"radarr.ataraxiadev.com"
"file.ataraxiadev.com"
"lidarr.ataraxiadev.com"
"cocalc.ataraxiadev.com"
"kavita.ataraxiadev.com"
2023-04-08 18:17:14 +03:00
"tools.ataraxiadev.com"
2023-04-25 17:24:01 +03:00
"home.ataraxiadev.com"
"matrix.ataraxiadev.com"
"cinny.ataraxiadev.com"
"dimension.ataraxiadev.com"
"stats.ataraxiadev.com"
"element.ataraxiadev.com"
2023-01-13 04:03:15 +03:00
];
2022-02-14 03:33:03 +03:00
};
};
2022-12-07 02:27:22 +03:00
services.fcgiwrap = {
enable = true;
user = config.services.nginx.user;
group = config.services.nginx.group;
};
2022-02-14 03:33:03 +03:00
services.nginx = {
enable = true;
group = "acme";
recommendedOptimisation = true;
recommendedGzipSettings = true;
recommendedTlsSettings = 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;
2023-03-23 01:58:10 +03:00
# proxy_hide_header Content-Security-Policy;
# add_header Content-Security-Policy "upgrade-insecure-requests";
# add_header X-XSS-Protection "1; mode=block";
# add_header X-Robots-Tag "none";
# add_header X-Content-Type-Options "nosniff";
2023-04-08 18:17:14 +03:00
2022-04-04 14:53:16 +03:00
'';
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 {
2023-04-08 18:17:14 +03:00
# "ataraxiadev.com" = default // authentik {
# root = { proxyPass = "http://127.0.0.1:3000"; };
# rootExtraConfig = ''
# if ($http_origin ~* "^https?://\w*\.?ataraxiadev\.com$") {
# add_header Access-Control-Allow-Origin "$http_origin";
# }
# '' + proxySettings;
# };
2022-02-14 03:33:03 +03:00
"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;
'';
};
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;
2023-04-25 17:24:01 +03:00
"matrix:443" = {
serverAliases = [
"matrix.ataraxiadev.com"
"cinny.ataraxiadev.com"
"dimension.ataraxiadev.com"
"element.ataraxiadev.com"
"stats.ataraxiadev.com"
];
listen = [{
addr = "0.0.0.0";
port = 443;
ssl = true;
}];
2022-02-19 00:15:28 +03:00
locations."/" = {
2023-04-25 17:24:01 +03:00
proxyPass = "http://matrix.pve:81";
extraConfig = ''
# proxy_hide_header Content-Security-Policy;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
client_max_body_size 50M;
'';
2022-02-19 00:15:28 +03:00
};
} // default;
2023-04-25 17:24:01 +03:00
"matrix:8448" = with config.security.acme; {
serverAliases = [ "matrix.ataraxiadev.com" ];
listen = [{
addr = "0.0.0.0";
port = 8448;
ssl = true;
}];
locations."/" = {
proxyPass = "http://matrix.pve:8449";
extraConfig = ''
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
client_max_body_size 50M;
'';
};
} // default;
"home.ataraxiadev.com" = default // authentik {
root = { proxyPass = "http://127.0.0.1:3000"; };
};
2022-02-21 02:25:13 +03:00
"vw.ataraxiadev.com" = {
locations."/" = {
2023-04-08 18:17:14 +03:00
proxyPass = "http://127.0.0.1:8812";
2022-10-09 00:39:52 +03:00
extraConfig = proxySettings;
};
2022-02-21 02:25:13 +03:00
locations."/notifications/hub" = {
2023-04-08 18:17:14 +03:00
proxyPass = "http://127.0.0.1:3012";
2022-02-21 02:25:13 +03:00
proxyWebsockets = true;
2022-10-09 00:39:52 +03:00
extraConfig = proxySettings;
};
2022-02-21 02:25:13 +03:00
locations."/notifications/hub/negotiate" = {
2023-04-08 18:17:14 +03:00
proxyPass = "http://127.0.0.1:8812";
2022-10-09 00:39:52 +03:00
extraConfig = proxySettings;
};
2022-02-21 02:25:13 +03:00
} // default;
2022-03-10 19:12:07 +03:00
"code.ataraxiadev.com" = {
locations."/" = {
2023-04-08 18:17:14 +03:00
proxyPass = "http://127.0.0.1:6000";
2022-10-09 00:39:52 +03:00
extraConfig = proxySettings;
};
2022-03-10 19:12:07 +03:00
} // default;
2023-03-23 01:58:10 +03:00
# "bathist.ataraxiadev.com" = {
2023-01-13 04:03:15 +03:00
# locations."/" = {
2023-04-08 18:17:14 +03:00
# proxyPass = "http://127.0.0.1:9999";
2023-01-13 04:03:15 +03:00
# extraConfig = proxySettings;
# };
# } // default;
2023-03-23 01:58:10 +03:00
"bathist.ataraxiadev.com" = default // authentik {
2023-04-08 18:17:14 +03:00
root = { proxyPass = "http://127.0.0.1:9999"; };
2023-03-23 01:58:10 +03:00
rootExtraConfig = proxySettings;
};
"browser.ataraxiadev.com" = {
locations."/" = {
2023-04-08 18:17:14 +03:00
proxyPass = "http://127.0.0.1:8090";
2023-03-23 01:58:10 +03:00
proxyWebsockets = true;
extraConfig = ''
proxy_read_timeout 86400;
'' + proxySettings;
};
} // default;
"fb.ataraxiadev.com" = default // authentik {
2023-04-08 18:17:14 +03:00
root = { proxyPass = "http://127.0.0.1:3923"; };
2023-03-23 01:58:10 +03:00
rootExtraConfig = ''
proxy_redirect off;
proxy_http_version 1.1;
client_max_body_size 0;
proxy_buffering off;
proxy_request_buffering off;
proxy_set_header Connection "Keep-Alive";
'' + proxySettings;
};
"file.ataraxiadev.com" = {
locations."/" = {
2023-04-08 18:17:14 +03:00
proxyPass = "http://127.0.0.1:8088";
2023-03-23 01:58:10 +03:00
extraConfig = ''
client_max_body_size 0;
2023-04-08 18:17:14 +03:00
proxy_buffer_size 16k;
proxy_busy_buffers_size 16k;
proxy_connect_timeout 36000s;
proxy_max_temp_file_size 102400m;
proxy_read_timeout 36000s;
proxy_request_buffering off;
send_timeout 36000s;
proxy_send_timeout 36000s;
# proxy_buffering off;
2023-03-23 01:58:10 +03:00
'' + proxySettings;
};
extraConfig = ''
proxy_set_header X-Forwarded-For $remote_addr;
'';
} // default;
2022-03-22 06:01:10 +03:00
"webmail.ataraxiadev.com" = {
locations."/" = {
extraConfig = ''
client_max_body_size 30M;
2022-10-09 00:39:52 +03:00
'' + proxySettings;
};
2022-04-04 14:53:16 +03:00
} // default;
2023-03-23 01:58:10 +03:00
"cocalc.ataraxiadev.com" = {
locations."/" = {
proxyPass = "https://localhost:9099";
proxyWebsockets = true;
extraConfig = proxySettings;
};
} // default;
2023-04-08 18:17:14 +03:00
"tools.ataraxiadev.com" = default // authentik {
root = { proxyPass = "http://127.0.0.1:8070"; };
};
2023-03-23 01:58:10 +03:00
"media-stack" = {
serverAliases = [
"jellyfin.ataraxiadev.com"
"qbit.ataraxiadev.com"
"medusa.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 = ''
# For Medusa
add_header Content-Security-Policy "upgrade-insecure-requests";
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;
2023-01-13 04:03:15 +03:00
# "microbin.ataraxiadev.com" = {
# locations."/" = {
2023-04-08 18:17:14 +03:00
# proxyPass = "http://127.0.0.1:9988";
2023-01-13 04:03:15 +03:00
# extraConfig = ''
# client_max_body_size 40M;
# '' + proxySettings;
# };
# } // default;
2023-01-26 00:43:11 +03:00
"joplin.ataraxiadev.com" = {
locations."/" = {
2023-04-08 18:17:14 +03:00
proxyPass = "http://127.0.0.1:22300";
2023-01-26 00:43:11 +03:00
extraConfig = proxySettings;
};
} // default;
"fsync.ataraxiadev.com" = {
locations."/" = {
2023-04-08 18:17:14 +03:00
proxyPass = "http://127.0.0.1:5000";
2023-01-26 00:43:11 +03:00
extraConfig = proxySettings;
};
} // default;
2023-01-26 04:45:14 +03:00
"auth.ataraxiadev.com" = {
locations."/" = {
2023-04-08 18:17:14 +03:00
proxyPass = "http://127.0.0.1:9000";
2023-03-23 01:58:10 +03:00
proxyWebsockets = true;
2023-01-26 04:45:14 +03:00
extraConfig = proxySettings;
};
} // default;
2023-03-23 01:58:10 +03:00
"ldap.ataraxiadev.com" = default;
2022-12-07 02:27:22 +03:00
"api.ataraxiadev.com" = {
locations."~ (\\.py|\\.sh)$" = with config.services; {
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;
2022-02-14 03:33:03 +03:00
};
};
2022-12-07 02:27:22 +03:00
secrets.narodmon-key.owner = config.services.nginx.user;
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
2022-02-14 03:33:03 +03:00
networking.firewall.allowedTCPPorts = [ 80 443 8448 ];
2022-05-18 01:23:15 +03:00
}