2020-08-24 15:07:55 +02:00
|
|
|
# Web services configuration
|
|
|
|
{ config, pkgs, lib, ... }: {
|
2019-11-10 23:40:31 +01:00
|
|
|
|
2020-09-02 18:44:31 +02:00
|
|
|
environment.systemPackages = with pkgs; [ libressl ];
|
2019-11-10 23:40:31 +01:00
|
|
|
|
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
|
|
|
recommendedTlsSettings = true;
|
|
|
|
recommendedGzipSettings = true;
|
|
|
|
recommendedProxySettings = true;
|
|
|
|
recommendedOptimisation = true;
|
2019-11-25 18:56:39 +01:00
|
|
|
clientMaxBodySize = "0";
|
2020-08-24 15:07:55 +02:00
|
|
|
sslCiphers =
|
|
|
|
"ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!3DES:!MD5:!PSK:!AES128";
|
2019-11-10 23:40:31 +01:00
|
|
|
sslProtocols = "TLSv1.2 TLSv1.3";
|
2019-11-14 00:31:39 +01:00
|
|
|
sslDhparam = "/var/lib/dhparams/nginx.pem";
|
2019-11-10 23:40:31 +01:00
|
|
|
commonHttpConfig = ''
|
|
|
|
# Add HSTS header with preloading to HTTPS requests.
|
|
|
|
# Adding this header to HTTP requests is discouraged
|
|
|
|
map $scheme $hsts_header {
|
|
|
|
https "max-age=31536000; includeSubdomains; preload";
|
|
|
|
}
|
|
|
|
add_header Strict-Transport-Security $hsts_header;
|
|
|
|
|
|
|
|
# Enable CSP for your services.
|
|
|
|
#add_header Content-Security-Policy "script-src 'self'; object-src 'none'; base-uri 'none';" always;
|
|
|
|
|
|
|
|
# Minimize information leaked to other domains
|
|
|
|
add_header 'Referrer-Policy' 'origin-when-cross-origin';
|
|
|
|
|
|
|
|
# Disable embedding as a frame
|
|
|
|
add_header X-Frame-Options DENY;
|
|
|
|
|
|
|
|
# Prevent injection of code in other mime types (XSS Attacks)
|
|
|
|
add_header X-Content-Type-Options nosniff;
|
|
|
|
|
|
|
|
# Enable XSS protection of the browser.
|
|
|
|
# May be unnecessary when CSP is configured properly (see above)
|
|
|
|
add_header X-XSS-Protection "1; mode=block";
|
|
|
|
|
|
|
|
# This might create errors
|
|
|
|
proxy_cookie_path / "/; secure; HttpOnly; SameSite=strict";
|
|
|
|
'';
|
|
|
|
virtualHosts = {
|
|
|
|
"coolneng.duckdns.org" = {
|
|
|
|
enableACME = true;
|
|
|
|
forceSSL = true;
|
|
|
|
locations."/radicale/" = {
|
2020-08-24 15:07:55 +02:00
|
|
|
return = "301 https://radicale.coolneng.duckdns.org";
|
2019-11-10 23:40:31 +01:00
|
|
|
};
|
2019-11-13 00:00:04 +01:00
|
|
|
locations."/syncthing/" = {
|
2020-08-24 15:07:55 +02:00
|
|
|
return = "301 https://sync.coolneng.duckdns.org";
|
2019-11-13 00:00:04 +01:00
|
|
|
};
|
2019-11-25 15:19:01 +01:00
|
|
|
locations."/gitea/" = {
|
2020-08-24 15:07:55 +02:00
|
|
|
extraConfig =
|
|
|
|
"rewrite ^/gitea/(.*)$ https://git.coolneng.duckdns.org/$1 last;";
|
2019-11-16 10:55:10 +01:00
|
|
|
};
|
2019-11-17 23:25:54 +01:00
|
|
|
locations."/miniflux/" = {
|
2020-08-24 15:07:55 +02:00
|
|
|
extraConfig =
|
|
|
|
"rewrite ^/miniflux/(.*)$ https://rss.coolneng.duckdns.org/$1 last;";
|
2019-11-17 23:25:54 +01:00
|
|
|
};
|
2020-08-24 15:07:55 +02:00
|
|
|
};
|
|
|
|
"radicale.coolneng.duckdns.org" = {
|
|
|
|
enableACME = true;
|
|
|
|
forceSSL = true;
|
|
|
|
locations."/" = {
|
|
|
|
proxyPass = "http://localhost:5232/";
|
|
|
|
extraConfig = ''
|
|
|
|
proxy_set_header X-Script-Name /;
|
|
|
|
proxy_pass_header Authorization;
|
|
|
|
'';
|
2019-11-17 18:58:31 +01:00
|
|
|
};
|
2019-11-10 23:40:31 +01:00
|
|
|
};
|
2020-08-24 15:07:55 +02:00
|
|
|
"sync.coolneng.duckdns.org" = {
|
|
|
|
enableACME = true;
|
|
|
|
forceSSL = true;
|
|
|
|
locations."/" = { proxyPass = "http://localhost:8384/"; };
|
|
|
|
};
|
|
|
|
"git.coolneng.duckdns.org" = {
|
|
|
|
enableACME = true;
|
|
|
|
forceSSL = true;
|
|
|
|
locations."/" = { proxyPass = "http://localhost:3000/"; };
|
|
|
|
};
|
|
|
|
"rss.coolneng.duckdns.org" = {
|
|
|
|
enableACME = true;
|
|
|
|
forceSSL = true;
|
|
|
|
locations."/" = { proxyPass = "http://localhost:8080/"; };
|
|
|
|
};
|
2019-11-10 23:40:31 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
# ACME certs configuration
|
2020-04-22 02:31:56 +02:00
|
|
|
security.acme = {
|
|
|
|
acceptTerms = true;
|
|
|
|
email = "akasroua@gmail.com";
|
|
|
|
certs = {
|
|
|
|
"coolneng.duckdns.org" = {
|
2020-10-28 00:39:32 +01:00
|
|
|
extraDomainNames = [
|
|
|
|
"radicale.coolneng.duckdns.org"
|
|
|
|
"sync.coolneng.duckdns.org"
|
|
|
|
"git.coolneng.duckdns.org"
|
|
|
|
"rss.coolneng.duckdns.org"
|
|
|
|
];
|
2020-04-22 02:31:56 +02:00
|
|
|
};
|
2019-11-10 23:40:31 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-11-14 02:30:12 +01:00
|
|
|
# Generate dhparams
|
2019-11-14 00:31:39 +01:00
|
|
|
security.dhparams = {
|
|
|
|
enable = true;
|
|
|
|
params = { nginx.bits = 2048; };
|
|
|
|
};
|
2019-11-10 23:40:31 +01:00
|
|
|
|
2019-11-17 18:58:31 +01:00
|
|
|
# PostgreSQL databases configuration
|
2019-11-16 10:55:10 +01:00
|
|
|
services.postgresql = {
|
|
|
|
enable = true;
|
2020-12-22 15:42:46 +01:00
|
|
|
package = pkgs.postgresql_11;
|
2019-11-17 23:50:48 +01:00
|
|
|
ensureDatabases = [ "gitea" "wallabag" ];
|
2019-11-16 10:55:10 +01:00
|
|
|
ensureUsers = [
|
|
|
|
{
|
2020-08-24 15:07:55 +02:00
|
|
|
name = "gitea";
|
|
|
|
ensurePermissions = { "DATABASE gitea" = "ALL PRIVILEGES"; };
|
2019-11-16 10:55:10 +01:00
|
|
|
}
|
2019-11-17 18:58:31 +01:00
|
|
|
{
|
2020-08-24 15:07:55 +02:00
|
|
|
name = "wallabag";
|
|
|
|
ensurePermissions = { "DATABASE wallabag" = "ALL PRIVILEGES"; };
|
2019-11-17 18:58:31 +01:00
|
|
|
}
|
2019-11-16 10:55:10 +01:00
|
|
|
];
|
|
|
|
authentication = lib.mkForce ''
|
2020-08-24 15:07:55 +02:00
|
|
|
# Generated file; do not edit!
|
|
|
|
# TYPE DATABASE USER ADDRESS METHOD
|
|
|
|
local all all trust
|
|
|
|
host all all 127.0.0.1/32 trust
|
|
|
|
host all all ::1/128 trust
|
2019-11-16 10:55:10 +01:00
|
|
|
'';
|
|
|
|
identMap = ''
|
2020-08-24 15:07:55 +02:00
|
|
|
gitea-users gitea gitea
|
2019-11-16 10:55:10 +01:00
|
|
|
'';
|
|
|
|
};
|
2019-11-14 02:30:12 +01:00
|
|
|
|
2019-11-17 18:58:31 +01:00
|
|
|
# PostgreSQL daily backups
|
2019-11-14 02:30:12 +01:00
|
|
|
services.postgresqlBackup = {
|
2020-08-24 15:07:55 +02:00
|
|
|
enable = true;
|
|
|
|
backupAll = true;
|
|
|
|
location = "/vault/backups/zion/databases";
|
|
|
|
startAt = "*-*-* 05:15:00";
|
2019-11-14 02:30:12 +01:00
|
|
|
};
|
|
|
|
|
2019-11-17 23:50:48 +01:00
|
|
|
# Miniflux configuration
|
2019-11-17 23:25:54 +01:00
|
|
|
services.miniflux = {
|
|
|
|
enable = true;
|
2019-11-17 23:50:48 +01:00
|
|
|
adminCredentialsFile = "/var/keys/miniflux/admin";
|
2019-11-17 23:25:54 +01:00
|
|
|
config = {
|
2020-08-24 15:07:55 +02:00
|
|
|
BASE_URL = "https://rss.coolneng.duckdns.org";
|
2020-04-22 02:31:56 +02:00
|
|
|
RUN_MIGRATIONS = "1";
|
2019-11-17 23:25:54 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-04-17 00:47:17 +02:00
|
|
|
# Restart reverse proxy after services startup
|
2020-08-24 15:07:55 +02:00
|
|
|
systemd.services.nginx.after = [
|
|
|
|
"gitea.service"
|
|
|
|
"syncthing.service"
|
|
|
|
"miniflux.service"
|
|
|
|
"radicale.service"
|
|
|
|
];
|
2019-11-10 23:40:31 +01:00
|
|
|
}
|