Init
Initial commit, nodes are mostly done, panel is WIP
This commit is contained in:
commit
c11e41669b
71 files changed
+3256
No files matched your search
@@ -0,0 +1,150 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
let
|
||||
cfg = config.vps.remnawave;
|
||||
domain = config.sops.placeholder."domain";
|
||||
panelName = "${cfg.subdomain}.${domain}";
|
||||
subName = "sub.${domain}";
|
||||
authName = "ta.${domain}";
|
||||
in
|
||||
{
|
||||
config = mkIf (cfg.enable && cfg.type == "panel") {
|
||||
sops.secrets = {
|
||||
"domain" = { };
|
||||
"letsencrypt/email" = { };
|
||||
"porkbun/api-key" = { };
|
||||
"porkbun/secret-key" = { };
|
||||
};
|
||||
|
||||
sops.templates."letsencrypt.env" = {
|
||||
mode = "0400";
|
||||
content = ''
|
||||
DOMAIN=${domain}
|
||||
LEGO_EMAIL=${config.sops.placeholder."letsencrypt/email"}
|
||||
PORKBUN_API_KEY=${config.sops.placeholder."porkbun/api-key"}
|
||||
PORKBUN_SECRET_API_KEY=${config.sops.placeholder."porkbun/secret-key"}
|
||||
'';
|
||||
};
|
||||
|
||||
sops.templates."nginx.conf" = {
|
||||
mode = "0444";
|
||||
content = ''
|
||||
map $http_upgrade $connection_upgrade {
|
||||
default upgrade;
|
||||
"" close;
|
||||
}
|
||||
|
||||
ssl_ecdh_curve X25519:prime256v1:secp384r1;
|
||||
ssl_prefer_server_ciphers on;
|
||||
ssl_session_timeout 1d;
|
||||
ssl_session_cache shared:MozSSL:10m;
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name ${panelName} ${subName} ${authName};
|
||||
return 301 https://$host$request_uri;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl;
|
||||
listen [::]:443 ssl;
|
||||
http2 on;
|
||||
server_name ${panelName};
|
||||
ssl_certificate /var/lib/certs/live/fullchain.pem;
|
||||
ssl_certificate_key /var/lib/certs/live/privkey.pem;
|
||||
|
||||
location = /tinyauth {
|
||||
internal;
|
||||
proxy_pass http://127.0.0.1:3002/api/auth/nginx;
|
||||
proxy_pass_request_body off;
|
||||
proxy_set_header Content-Length "";
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-Forwarded-Host $host;
|
||||
proxy_set_header X-Forwarded-Uri $request_uri;
|
||||
proxy_set_header X-Api-Key $http_x_api_key;
|
||||
proxy_set_header Authorization $http_authorization;
|
||||
}
|
||||
|
||||
location / {
|
||||
auth_request /tinyauth;
|
||||
auth_request_set $tinyauth_location $upstream_http_x_tinyauth_location;
|
||||
error_page 401 403 =302 $tinyauth_location;
|
||||
|
||||
proxy_http_version 1.1;
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
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-Port $server_port;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection $connection_upgrade;
|
||||
proxy_set_header Authorization $http_authorization;
|
||||
proxy_set_header X-Api-Key "";
|
||||
proxy_read_timeout 60s;
|
||||
proxy_send_timeout 60s;
|
||||
}
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl;
|
||||
listen [::]:443 ssl;
|
||||
http2 on;
|
||||
server_name ${subName};
|
||||
ssl_certificate /var/lib/certs/live/fullchain.pem;
|
||||
ssl_certificate_key /var/lib/certs/live/privkey.pem;
|
||||
|
||||
location / {
|
||||
proxy_http_version 1.1;
|
||||
proxy_pass http://127.0.0.1:3010;
|
||||
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 Upgrade $http_upgrade;
|
||||
proxy_set_header Connection $connection_upgrade;
|
||||
}
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl;
|
||||
listen [::]:443 ssl;
|
||||
http2 on;
|
||||
server_name ${authName};
|
||||
ssl_certificate /var/lib/certs/live/fullchain.pem;
|
||||
ssl_certificate_key /var/lib/certs/live/privkey.pem;
|
||||
|
||||
location / {
|
||||
proxy_http_version 1.1;
|
||||
proxy_pass http://127.0.0.1:3002;
|
||||
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 Upgrade $http_upgrade;
|
||||
proxy_set_header Connection $connection_upgrade;
|
||||
}
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80 default_server;
|
||||
listen [::]:80 default_server;
|
||||
listen 443 ssl default_server;
|
||||
listen [::]:443 ssl default_server;
|
||||
http2 on;
|
||||
server_name _;
|
||||
ssl_certificate /var/lib/certs/live/fullchain.pem;
|
||||
ssl_certificate_key /var/lib/certs/live/privkey.pem;
|
||||
ssl_reject_handshake on;
|
||||
return 444;
|
||||
}
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
let
|
||||
cfg = config.vps.remnawave;
|
||||
letsencryptScript = pkgs.writeShellScript "letsencrypt-wildcard" ''
|
||||
set -eu
|
||||
|
||||
install -d -m 0755 /var/lib/certs/live
|
||||
install -d -m 0700 /var/lib/lego
|
||||
|
||||
lego run \
|
||||
--accept-tos \
|
||||
--email "$LEGO_EMAIL" \
|
||||
--dns porkbun \
|
||||
--path /var/lib/lego \
|
||||
--domains "*.$DOMAIN" \
|
||||
--renew-days 30
|
||||
|
||||
install -m 0644 "/var/lib/lego/certificates/_.$DOMAIN.crt" /var/lib/certs/live/fullchain.pem
|
||||
install -m 0640 -g nginx "/var/lib/lego/certificates/_.$DOMAIN.key" /var/lib/certs/live/privkey.pem
|
||||
|
||||
if [ -s /run/nginx/nginx.pid ] && kill -0 "$(cat /run/nginx/nginx.pid)" 2>/dev/null; then
|
||||
${pkgs.nginx}/bin/nginx -s reload
|
||||
fi
|
||||
'';
|
||||
in
|
||||
{
|
||||
imports = [ ./config.nix ];
|
||||
|
||||
config = mkIf (cfg.enable && cfg.type == "panel") {
|
||||
environment.systemPackages = [ pkgs.lego ];
|
||||
|
||||
services.nginx = {
|
||||
enable = true;
|
||||
recommendedGzipSettings = true;
|
||||
sslProtocols = "TLSv1.2 TLSv1.3";
|
||||
appendHttpConfig = ''
|
||||
include ${config.sops.templates."nginx.conf".path};
|
||||
'';
|
||||
};
|
||||
|
||||
systemd.services.nginx = {
|
||||
after = [
|
||||
"sops-nix.service"
|
||||
"letsencrypt-wildcard.service"
|
||||
"docker-tinyauth.service"
|
||||
"docker-remnapanel.service"
|
||||
"docker-remnawave-subpage.service"
|
||||
];
|
||||
requires = [ "letsencrypt-wildcard.service" ];
|
||||
wants = [
|
||||
"sops-nix.service"
|
||||
"docker-tinyauth.service"
|
||||
"docker-remnapanel.service"
|
||||
"docker-remnawave-subpage.service"
|
||||
];
|
||||
};
|
||||
|
||||
systemd.services.letsencrypt-wildcard = {
|
||||
description = "Issue a wildcard certificate for domain";
|
||||
requiredBy = [ "nginx.service" ];
|
||||
before = [ "nginx.service" ];
|
||||
after = [
|
||||
"network-online.target"
|
||||
"sops-nix.service"
|
||||
];
|
||||
wants = [
|
||||
"network-online.target"
|
||||
"sops-nix.service"
|
||||
];
|
||||
path = with pkgs; [
|
||||
coreutils
|
||||
lego
|
||||
];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
RemainAfterExit = true;
|
||||
EnvironmentFile = config.sops.templates."letsencrypt.env".path;
|
||||
ExecStart = letsencryptScript;
|
||||
};
|
||||
};
|
||||
|
||||
systemd.services.letsencrypt-wildcard-renew = {
|
||||
description = "Renew a wildcard certificate";
|
||||
after = [
|
||||
"network-online.target"
|
||||
"sops-nix.service"
|
||||
"letsencrypt-wildcard.service"
|
||||
];
|
||||
wants = [
|
||||
"network-online.target"
|
||||
"sops-nix.service"
|
||||
];
|
||||
path = with pkgs; [
|
||||
coreutils
|
||||
lego
|
||||
];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
EnvironmentFile = config.sops.templates."letsencrypt.env".path;
|
||||
ExecStart = letsencryptScript;
|
||||
};
|
||||
};
|
||||
|
||||
systemd.timers.letsencrypt-wildcard-renew = {
|
||||
wantedBy = [ "timers.target" ];
|
||||
timerConfig = {
|
||||
OnBootSec = "60d";
|
||||
OnUnitActiveSec = "60d";
|
||||
Persistent = true;
|
||||
};
|
||||
};
|
||||
|
||||
systemd.tmpfiles.rules = [
|
||||
"d /var/lib/certs/live 0755 root root -"
|
||||
"d /var/lib/lego 0700 root root -"
|
||||
];
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user