253 lines
7.8 KiB
Nix
Raw Normal View History

2022-02-14 03:33:03 +03:00
{ config, lib, pkgs, ... }: {
security.acme = {
acceptTerms = true;
2022-04-04 14:53:16 +03:00
# defaults.server = "https://acme-staging-v02.api.letsencrypt.org/directory"; # staging
defaults.server = "https://acme-v02.api.letsencrypt.org/directory"; # production
2022-03-10 19:12:07 +03:00
defaults.email = "ataraxiadev@ataraxiadev.com";
2022-04-04 14:53:16 +03:00
defaults.renewInterval = "weekly";
2022-02-14 03:33:03 +03:00
certs = {
"ataraxiadev.com" = {
webroot = "/var/lib/acme/acme-challenge";
extraDomainNames = [
"matrix.ataraxiadev.com"
"cinny.ataraxiadev.com"
"dimension.ataraxiadev.com"
"element.ataraxiadev.com"
"goneb.ataraxiadev.com"
"jitsi.ataraxiadev.com"
"stats.ataraxiadev.com"
2022-02-19 00:15:28 +03:00
"startpage.ataraxiadev.com"
2022-02-21 02:25:13 +03:00
"vw.ataraxiadev.com"
2022-03-10 19:12:07 +03:00
"code.ataraxiadev.com"
2022-03-22 06:02:13 +03:00
"file.ataraxiadev.com"
2022-03-22 06:01:10 +03:00
"webmail.ataraxiadev.com"
2022-04-04 14:53:16 +03:00
"jellyfin.ataraxiadev.com"
"radarr.ataraxiadev.com"
"qbit.ataraxiadev.com"
"prowlarr.ataraxiadev.com"
"sonarr.ataraxiadev.com"
"sonarrtv.ataraxiadev.com"
"organizr.ataraxiadev.com"
"lidarr.ataraxiadev.com"
"bazarr.ataraxiadev.com"
2022-04-09 21:36:25 +03:00
"nzbhydra.ataraxiadev.com"
"kavita.ataraxiadev.com"
2022-05-19 21:46:31 +03:00
"shoko.ataraxiadev.com"
2022-08-05 21:03:54 +03:00
"bathist.ataraxiadev.com"
2022-08-31 11:37:26 +03:00
"microbin.ataraxiadev.com"
2022-10-09 00:39:52 +03:00
"joplin.ataraxiadev.com"
2023-01-03 23:48:59 +03:00
"api.ataraxiadev.com"
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;
2022-05-18 01:23:15 +03:00
proxy_hide_header Content-Security-Policy;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag "none";
add_header X-Content-Type-Options "nosniff";
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 {
"ataraxiadev.com" = {
2022-11-20 19:14:20 +03:00
locations."/" = {
root = "/srv/http/ataraxiadev.com/";
extraConfig = ''
try_files $uri $uri/ =404;
'';
};
2022-02-14 03:33:03 +03:00
locations."/.well-known/matrix" = {
proxyPass = "https://matrix.ataraxiadev.com/.well-known/matrix";
extraConfig = ''
proxy_set_header X-Forwarded-For $remote_addr;
'';
2022-03-10 19:12:07 +03:00
};
2022-02-14 03:33:03 +03:00
} // default;
"matrix:443" = {
serverAliases = [
"matrix.ataraxiadev.com"
"cinny.ataraxiadev.com"
"dimension.ataraxiadev.com"
"element.ataraxiadev.com"
"goneb.ataraxiadev.com"
"jitsi.ataraxiadev.com"
"stats.ataraxiadev.com"
];
listen = [{
addr = "0.0.0.0";
port = 443;
ssl = true;
}];
locations."/" = {
2022-03-10 19:12:07 +03:00
proxyPass = "http://matrix.pve:81";
2022-05-19 21:46:31 +03:00
extraConfig = ''
proxy_hide_header Content-Security-Policy;
2022-10-09 00:39:52 +03:00
'' + proxySettings;
2022-05-19 21:46:31 +03:00
};
2022-02-14 03:33:03 +03:00
} // default;
2022-12-07 02:28:00 +03:00
"matrix:8448" = let
certName = default.useACMEHost;
in with config.security.acme; {
onlySSL = true;
sslCertificate = "${certs.${certName}.directory}/fullchain.pem";
sslCertificateKey = "${certs.${certName}.directory}/key.pem";
sslTrustedCertificate = "${certs.${certName}.directory}/chain.pem";
2022-02-14 03:33:03 +03:00
serverAliases = [ "matrix.ataraxiadev.com" ];
listen = [{
addr = "0.0.0.0";
port = 8448;
ssl = true;
}];
locations."/" = {
2022-03-10 19:12:07 +03:00
proxyPass = "http://matrix.pve:8449";
2022-10-09 00:39:52 +03:00
extraConfig = proxySettings;
};
2022-12-07 02:28:00 +03:00
};
2022-02-19 00:15:28 +03:00
"startpage.ataraxiadev.com" = {
locations."/" = {
root = "/srv/http/startpage.ataraxiadev.com/";
2022-10-09 00:39:52 +03:00
# extraConfig = hardened;
2022-02-19 00:15:28 +03:00
};
} // default;
2022-02-21 02:25:13 +03:00
"vw.ataraxiadev.com" = {
locations."/" = {
proxyPass = "http://localhost:8812";
2022-10-09 00:39:52 +03:00
extraConfig = proxySettings;
};
2022-02-21 02:25:13 +03:00
locations."/notifications/hub" = {
proxyPass = "http://localhost:3012";
proxyWebsockets = true;
2022-10-09 00:39:52 +03:00
extraConfig = proxySettings;
};
2022-02-21 02:25:13 +03:00
locations."/notifications/hub/negotiate" = {
proxyPass = "http://localhost: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."/" = {
proxyPass = "http://localhost:6000";
2022-10-09 00:39:52 +03:00
extraConfig = proxySettings;
};
2022-03-10 19:12:07 +03:00
} // default;
2022-08-05 21:03:54 +03:00
"bathist.ataraxiadev.com" = {
locations."/" = {
proxyPass = "http://localhost:9999";
2022-10-09 00:39:52 +03:00
extraConfig = proxySettings;
};
2022-08-05 21:03:54 +03:00
} // default;
2022-03-22 06:02:13 +03:00
"file.ataraxiadev.com" = {
locations."/" = {
2022-04-04 14:53:16 +03:00
proxyPass = "http://localhost:8088";
2022-10-09 00:39:52 +03:00
extraConfig = proxySettings;
};
2022-03-22 06:02:13 +03:00
} // 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;
"media-stack" = {
serverAliases = [
"jellyfin.ataraxiadev.com"
"radarr.ataraxiadev.com"
"qbit.ataraxiadev.com"
"prowlarr.ataraxiadev.com"
"sonarr.ataraxiadev.com"
"sonarrtv.ataraxiadev.com"
"organizr.ataraxiadev.com"
"lidarr.ataraxiadev.com"
"bazarr.ataraxiadev.com"
2022-04-09 21:36:25 +03:00
"nzbhydra.ataraxiadev.com"
"kavita.ataraxiadev.com"
2022-05-19 21:46:31 +03:00
"shoko.ataraxiadev.com"
2022-04-04 14:53:16 +03:00
];
locations."/" = {
proxyPass = "http://localhost:8100";
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;
2022-10-09 00:39:52 +03:00
'' + proxySettings;
2022-04-04 14:53:16 +03:00
};
2022-03-22 06:01:10 +03:00
} // default;
2022-08-31 11:37:26 +03:00
"microbin.ataraxiadev.com" = {
locations."/" = {
proxyPass = "http://localhost:9988";
extraConfig = ''
client_max_body_size 40M;
2022-10-09 00:39:52 +03:00
'' + proxySettings;
2022-10-01 22:46:29 +03:00
};
} // default;
2022-10-08 04:45:07 +03:00
"joplin.ataraxiadev.com" = {
locations."/" = {
proxyPass = "http://localhost:22300";
2022-10-09 00:39:52 +03:00
extraConfig = proxySettings;
2022-10-08 04:45:07 +03:00
};
} // 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 = ''
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-12-14 23:46:25 +03:00
persist.state.directories = [
"/var/lib/acme"
];
2022-05-18 01:23:15 +03:00
}