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,71 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
let
|
||||
cfg = config.vps.remnawave;
|
||||
targetName = "remnawave.target";
|
||||
remnaService =
|
||||
if cfg.type == "node" then
|
||||
"docker-remnanode.service"
|
||||
else if cfg.type == "panel" then
|
||||
"docker-remnapanel.service"
|
||||
else
|
||||
throw "Unknown remnawave type ${cfg.type}";
|
||||
units = [
|
||||
"nginx.service"
|
||||
remnaService
|
||||
]
|
||||
++ optionals (cfg.type == "panel") [
|
||||
"docker-remnawave-db.service"
|
||||
"docker-remnawave-valkey.service"
|
||||
"docker-remnawave-subpage.service"
|
||||
"docker-tinyauth.service"
|
||||
]
|
||||
++ optional cfg.zapret.enable "docker-ss-zapret2.service";
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
./node
|
||||
./panel
|
||||
];
|
||||
|
||||
options.vps.remnawave = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
};
|
||||
type = mkOption {
|
||||
type = types.enum [
|
||||
"node"
|
||||
"panel"
|
||||
];
|
||||
};
|
||||
subdomain = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
zapret.enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
systemd.targets.remnawave = {
|
||||
description = "Remnawave ${cfg.type} stack";
|
||||
wants = units;
|
||||
after = units;
|
||||
};
|
||||
|
||||
systemd.services.nginx.partOf = [ targetName ];
|
||||
systemd.services.docker-remnanode.partOf = mkIf (cfg.type == "node") [ targetName ];
|
||||
systemd.services.docker-remnapanel.partOf = mkIf (cfg.type == "panel") [ targetName ];
|
||||
systemd.services.docker-remnawave-db.partOf = mkIf (cfg.type == "panel") [ targetName ];
|
||||
systemd.services.docker-remnawave-valkey.partOf = mkIf (cfg.type == "panel") [ targetName ];
|
||||
systemd.services.docker-remnawave-subpage.partOf = mkIf (cfg.type == "panel") [ targetName ];
|
||||
systemd.services.docker-tinyauth.partOf = mkIf (cfg.type == "panel") [ targetName ];
|
||||
systemd.services.docker-ss-zapret2.partOf = mkIf cfg.zapret.enable [ targetName ];
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
imports = [
|
||||
./nginx
|
||||
./remnanode
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
{ config, lib, ... }:
|
||||
with lib;
|
||||
let
|
||||
cfg = config.vps.remnawave;
|
||||
domain = config.sops.placeholder."domain";
|
||||
serverName = "${cfg.subdomain}.${domain}";
|
||||
in
|
||||
{
|
||||
config = mkIf (cfg.enable && cfg.type == "node") {
|
||||
sops.secrets = {
|
||||
"domain" = { };
|
||||
"letsencrypt/email" = { };
|
||||
"porkbun/api-key" = { };
|
||||
"porkbun/secret-key" = { };
|
||||
};
|
||||
|
||||
sops.templates."letsencrypt.env" = {
|
||||
mode = "0400";
|
||||
content = ''
|
||||
DOMAIN=${config.sops.placeholder."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 = ''
|
||||
ssl_ecdh_curve X25519:prime256v1:secp384r1;
|
||||
ssl_prefer_server_ciphers on;
|
||||
ssl_session_timeout 1d;
|
||||
ssl_session_cache shared:MozSSL:10m;
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name ${serverName};
|
||||
root /var/lib/vps/decoy;
|
||||
log_not_found off;
|
||||
add_header X-Robots-Tag "noindex, nofollow, noarchive, nosnippet, noimageindex" always;
|
||||
location / {
|
||||
try_files /index.html =404;
|
||||
}
|
||||
}
|
||||
|
||||
server {
|
||||
server_name ${serverName};
|
||||
listen unix:/dev/shm/nginx.sock ssl proxy_protocol;
|
||||
http2 on;
|
||||
ssl_certificate /var/lib/certs/live/fullchain.pem;
|
||||
ssl_certificate_key /var/lib/certs/live/privkey.pem;
|
||||
ssl_trusted_certificate /var/lib/certs/live/fullchain.pem;
|
||||
|
||||
location /xhttp/ {
|
||||
client_max_body_size 0;
|
||||
grpc_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
client_body_timeout 5m;
|
||||
grpc_read_timeout 315;
|
||||
grpc_send_timeout 5m;
|
||||
grpc_pass unix:/dev/shm/xrxh.socket;
|
||||
}
|
||||
|
||||
root /var/lib/vps/decoy;
|
||||
log_not_found off;
|
||||
add_header X-Robots-Tag "noindex, nofollow, noarchive, nosnippet, noimageindex" always;
|
||||
location / {
|
||||
try_files /index.html =404;
|
||||
}
|
||||
}
|
||||
|
||||
server {
|
||||
listen unix:/dev/shm/nginx.sock ssl proxy_protocol default_server;
|
||||
server_name _;
|
||||
add_header X-Robots-Tag "noindex, nofollow, noarchive, nosnippet, noimageindex" always;
|
||||
ssl_reject_handshake on;
|
||||
return 444;
|
||||
}
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
let
|
||||
cfg = config.vps.remnawave;
|
||||
decoySrc = pkgs.fetchFromGitHub {
|
||||
owner = "RomanTrifanov";
|
||||
repo = "sni-templates";
|
||||
rev = "0af61c18266120953d86a729ad01fe3a9a33a922";
|
||||
sha256 = "0bjy152mh4yry55wfpwkzlyhnnk92pq11xakr9wm3jas2dnn28i9";
|
||||
};
|
||||
decoy = pkgs.runCommand "decoy-site" { } ''
|
||||
mkdir -p "$out"
|
||||
cp -a ${decoySrc}/"503 error pages"/v1/. "$out"/
|
||||
'';
|
||||
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 == "node") {
|
||||
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"
|
||||
];
|
||||
requires = [ "letsencrypt-wildcard.service" ];
|
||||
wants = [ "sops-nix.service" ];
|
||||
preStart = lib.mkBefore ''
|
||||
rm -f /dev/shm/nginx.sock
|
||||
'';
|
||||
};
|
||||
|
||||
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/vps 0755 root root -"
|
||||
"L+ /var/lib/vps/decoy - - - - ${decoy}"
|
||||
];
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{ config, lib, ... }:
|
||||
with lib;
|
||||
let
|
||||
cfg = config.vps.remnawave;
|
||||
in
|
||||
{
|
||||
config = mkIf (cfg.enable && cfg.type == "node") {
|
||||
sops.secrets = {
|
||||
"remnanode/secret-key" = { };
|
||||
};
|
||||
|
||||
sops.templates."remnanode.env".content = ''
|
||||
NODE_PORT=${toString cfg.node.port}
|
||||
SECRET_KEY=${config.sops.placeholder."remnanode/secret-key"}
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
{ config, lib, ... }:
|
||||
with lib;
|
||||
let
|
||||
cfg = config.vps.remnawave;
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
./config.nix
|
||||
./zapret-dat.nix
|
||||
./roscomvpn-geosite.nix
|
||||
];
|
||||
|
||||
options.vps.remnawave.node = {
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 2222;
|
||||
};
|
||||
roscomvpnGeosite = mkEnableOption "roscomvpn geosite dat";
|
||||
};
|
||||
|
||||
config = mkIf (cfg.enable && cfg.type == "node") {
|
||||
virtualisation.oci-containers.containers.remnanode = {
|
||||
image = "docker.io/remnawave/node:2.8.0";
|
||||
autoStart = true;
|
||||
environmentFiles = [ config.sops.templates."remnanode.env".path ];
|
||||
volumes = [
|
||||
"/dev/shm:/dev/shm"
|
||||
]
|
||||
++ optional cfg.zapret.enable "/var/lib/remnanode/zapret.dat:/usr/local/bin/zapret.dat:ro"
|
||||
++ optional cfg.node.roscomvpnGeosite "/var/lib/remnanode/roscomvpn-geosite.dat:/usr/local/bin/roscomvpn-geosite.dat:ro";
|
||||
log-driver = "journald";
|
||||
extraOptions = [
|
||||
"--network=host"
|
||||
"--ulimit=nofile=1048576:1048576"
|
||||
"--cap-add=NET_ADMIN"
|
||||
];
|
||||
};
|
||||
|
||||
systemd.services.docker-remnanode = {
|
||||
after = [
|
||||
"nginx.service"
|
||||
"sops-nix.service"
|
||||
]
|
||||
++ optional cfg.zapret.enable "zapret-dat-update.service"
|
||||
++ optional cfg.node.roscomvpnGeosite "roscomvpn-geosite-update.service";
|
||||
wants = [
|
||||
"sops-nix.service"
|
||||
]
|
||||
++ optional cfg.zapret.enable "zapret-dat-update.service"
|
||||
++ optional cfg.node.roscomvpnGeosite "roscomvpn-geosite-update.service";
|
||||
serviceConfig.LimitNOFILE = 1048576;
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
let
|
||||
cfg = config.vps.remnawave;
|
||||
script = pkgs.writeShellScript "roscomvpn-geosite-update" ''
|
||||
set -euo pipefail
|
||||
|
||||
dest=/var/lib/remnanode/roscomvpn-geosite.dat
|
||||
tmp=$(mktemp)
|
||||
|
||||
trap 'rm -f "$tmp"' EXIT
|
||||
|
||||
install -d -m 0755 /var/lib/remnanode
|
||||
|
||||
${pkgs.curl}/bin/curl -fsSL -o "$tmp" \
|
||||
https://github.com/hydraponique/roscomvpn-geosite/releases/latest/download/geosite.dat
|
||||
changed=0
|
||||
if [[ ! -f "$dest" ]] || ! ${pkgs.diffutils}/bin/cmp -s "$tmp" "$dest"; then
|
||||
install -m 0644 "$tmp" "$dest"
|
||||
changed=1
|
||||
fi
|
||||
|
||||
if [[ "''${1:-}" == --restart-if-changed && "$changed" == 1 ]] \
|
||||
&& systemctl is-active --quiet docker-remnanode; then
|
||||
systemctl try-restart docker-remnanode
|
||||
fi
|
||||
'';
|
||||
in
|
||||
{
|
||||
config = mkIf (cfg.enable && cfg.type == "node" && cfg.node.roscomvpnGeosite) {
|
||||
systemd.services.roscomvpn-geosite-update = {
|
||||
description = "Download and update roscomvpn-geosite.dat";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
before = [ "docker-remnanode.service" ];
|
||||
after = [ "network-online.target" ];
|
||||
wants = [ "network-online.target" ];
|
||||
serviceConfig.Type = "oneshot";
|
||||
script = "${script}";
|
||||
};
|
||||
|
||||
systemd.services.roscomvpn-geosite-refresh = {
|
||||
description = "Download roscomvpn-geosite.dat and restart remnanode when it changes";
|
||||
after = [ "network-online.target" ];
|
||||
wants = [ "network-online.target" ];
|
||||
serviceConfig.Type = "oneshot";
|
||||
script = "${script} --restart-if-changed";
|
||||
};
|
||||
|
||||
systemd.timers.roscomvpn-geosite-refresh = {
|
||||
wantedBy = [ "timers.target" ];
|
||||
timerConfig = {
|
||||
OnCalendar = "daily";
|
||||
Persistent = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
let
|
||||
cfg = config.vps.remnawave;
|
||||
script = pkgs.writeShellScript "zapret-dat-update" ''
|
||||
set -euo pipefail
|
||||
|
||||
dest=/var/lib/remnanode/zapret.dat
|
||||
tmp=$(mktemp)
|
||||
|
||||
trap 'rm -f "$tmp"' EXIT
|
||||
|
||||
install -d -m 0755 /var/lib/remnanode
|
||||
|
||||
${pkgs.curl}/bin/curl -fsSL -o "$tmp" \
|
||||
https://github.com/kutovoys/ru_gov_zapret/releases/latest/download/zapret.dat
|
||||
|
||||
changed=0
|
||||
if [[ ! -f "$dest" ]] || ! ${pkgs.diffutils}/bin/cmp -s "$tmp" "$dest"; then
|
||||
install -m 0644 "$tmp" "$dest"
|
||||
changed=1
|
||||
fi
|
||||
|
||||
if [[ "''${1:-}" == --restart-if-changed && "$changed" == 1 ]] \
|
||||
&& systemctl is-active --quiet docker-remnanode; then
|
||||
systemctl try-restart docker-remnanode
|
||||
fi
|
||||
'';
|
||||
in
|
||||
{
|
||||
config = mkIf (cfg.enable && cfg.type == "node" && cfg.zapret.enable) {
|
||||
systemd.services.zapret-dat-update = {
|
||||
description = "Download and update zapret.dat";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
before = [ "docker-remnanode.service" ];
|
||||
after = [ "network-online.target" ];
|
||||
wants = [ "network-online.target" ];
|
||||
serviceConfig.Type = "oneshot";
|
||||
script = "${script}";
|
||||
};
|
||||
|
||||
systemd.services.zapret-dat-refresh = {
|
||||
description = "Download zapret.dat and restart remnanode when it changes";
|
||||
after = [ "network-online.target" ];
|
||||
wants = [ "network-online.target" ];
|
||||
serviceConfig.Type = "oneshot";
|
||||
script = "${script} --restart-if-changed";
|
||||
};
|
||||
|
||||
systemd.timers.zapret-dat-refresh = {
|
||||
wantedBy = [ "timers.target" ];
|
||||
timerConfig = {
|
||||
OnCalendar = "daily";
|
||||
Persistent = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
let
|
||||
cfg = config.vps.remnawave;
|
||||
script = pkgs.writeShellScript "remnawave-backup" ''
|
||||
set -eu
|
||||
stamp=$(date -u +%Y%m%dT%H%M%SZ)
|
||||
dir=/var/lib/remnawave-backup
|
||||
out="$dir/remnawave-$stamp.sql.gz"
|
||||
install -d -m 0700 "$dir"
|
||||
${pkgs.docker}/bin/docker exec -e PGPASSWORD="$POSTGRES_PASSWORD" remnawave-db \
|
||||
pg_dump -U postgres postgres | ${pkgs.gzip}/bin/gzip -c > "$out"
|
||||
chmod 0600 "$out"
|
||||
|
||||
if [ -n "''${TELEGRAM_BOT_TOKEN:-}" ] && [ -n "''${TELEGRAM_CHAT_ID:-}" ]; then
|
||||
${pkgs.curl}/bin/curl -fsS \
|
||||
-F "chat_id=$TELEGRAM_CHAT_ID" \
|
||||
-F "document=@$out" \
|
||||
"https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendDocument" \
|
||||
|| echo "telegram backup upload failed" >&2
|
||||
fi
|
||||
|
||||
if [ -n "''${BACKUP_SSH_TARGET:-}" ]; then
|
||||
${pkgs.openssh}/bin/scp \
|
||||
-i ${config.sops.secrets."panel/backup-ssh-key".path} \
|
||||
-o StrictHostKeyChecking=accept-new \
|
||||
"$out" "$BACKUP_SSH_TARGET" \
|
||||
|| echo "netbird backup copy failed" >&2
|
||||
fi
|
||||
|
||||
ls -1t "$dir"/remnawave-*.sql.gz | tail -n +8 | xargs -r rm -f
|
||||
'';
|
||||
in
|
||||
{
|
||||
config = mkIf (cfg.enable && cfg.type == "panel") {
|
||||
sops.secrets = {
|
||||
"panel/postgres-password" = { };
|
||||
"panel/telegram-bot-token" = { };
|
||||
"panel/telegram-chat-id" = { };
|
||||
"panel/backup-ssh-target" = { };
|
||||
"panel/backup-ssh-key" = { };
|
||||
};
|
||||
|
||||
sops.templates."remnawave-backup.env" = {
|
||||
mode = "0400";
|
||||
content = ''
|
||||
POSTGRES_PASSWORD=${config.sops.placeholder."panel/postgres-password"}
|
||||
TELEGRAM_BOT_TOKEN=${config.sops.placeholder."panel/telegram-bot-token"}
|
||||
TELEGRAM_CHAT_ID=${config.sops.placeholder."panel/telegram-chat-id"}
|
||||
BACKUP_SSH_TARGET=${config.sops.placeholder."panel/backup-ssh-target"}
|
||||
'';
|
||||
};
|
||||
|
||||
systemd.services.remnawave-backup = {
|
||||
description = "Dump the panel database and send it out";
|
||||
after = [
|
||||
"docker-remnawave-db.service"
|
||||
"network-online.target"
|
||||
];
|
||||
wants = [ "docker-remnawave-db.service" ];
|
||||
path = [ pkgs.coreutils ];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
EnvironmentFile = config.sops.templates."remnawave-backup.env".path;
|
||||
ExecStart = script;
|
||||
};
|
||||
};
|
||||
|
||||
systemd.timers.remnawave-backup = {
|
||||
wantedBy = [ "timers.target" ];
|
||||
timerConfig = {
|
||||
OnCalendar = "daily";
|
||||
Persistent = true;
|
||||
RandomizedDelaySec = "30m";
|
||||
};
|
||||
};
|
||||
|
||||
systemd.tmpfiles.rules = [ "d /var/lib/remnawave-backup 0700 root root -" ];
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
imports = [
|
||||
./nginx
|
||||
./postgresql
|
||||
./valkey
|
||||
./remnapanel
|
||||
./sub-page
|
||||
./tinyauth.nix
|
||||
./backup.nix
|
||||
];
|
||||
}
|
||||
@@ -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 -"
|
||||
];
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
let
|
||||
cfg = config.vps.remnawave;
|
||||
in
|
||||
{
|
||||
config = mkIf (cfg.enable && cfg.type == "panel") {
|
||||
sops.secrets."panel/postgres-password" = { };
|
||||
|
||||
sops.templates."remnawave-db.env" = {
|
||||
mode = "0400";
|
||||
content = ''
|
||||
POSTGRES_USER=postgres
|
||||
POSTGRES_PASSWORD=${config.sops.placeholder."panel/postgres-password"}
|
||||
POSTGRES_DB=postgres
|
||||
TZ=UTC
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
let
|
||||
cfg = config.vps.remnawave;
|
||||
in
|
||||
{
|
||||
imports = [ ./config.nix ];
|
||||
|
||||
config = mkIf (cfg.enable && cfg.type == "panel") {
|
||||
virtualisation.oci-containers.containers.remnawave-db = {
|
||||
image = "docker.io/postgres:18.1";
|
||||
autoStart = true;
|
||||
environmentFiles = [ config.sops.templates."remnawave-db.env".path ];
|
||||
volumes = [ "remnawave-db-data:/var/lib/postgresql" ];
|
||||
log-driver = "journald";
|
||||
extraOptions = [
|
||||
"--network=remnawave"
|
||||
"--hostname=remnawave-db"
|
||||
"--ulimit=nofile=1048576:1048576"
|
||||
];
|
||||
};
|
||||
|
||||
systemd.services.docker-remnawave-db = {
|
||||
after = [
|
||||
"docker-remnawave-network.service"
|
||||
"sops-nix.service"
|
||||
];
|
||||
requires = [ "docker-remnawave-network.service" ];
|
||||
wants = [ "sops-nix.service" ];
|
||||
};
|
||||
};
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,36 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
let
|
||||
cfg = config.vps.remnawave;
|
||||
domain = config.sops.placeholder."domain";
|
||||
in
|
||||
{
|
||||
config = mkIf (cfg.enable && cfg.type == "panel") {
|
||||
sops.secrets = {
|
||||
"domain" = { };
|
||||
"panel/app-secret" = { };
|
||||
"panel/postgres-password" = { };
|
||||
};
|
||||
|
||||
sops.templates."remnapanel.env" = {
|
||||
mode = "0400";
|
||||
content = ''
|
||||
APP_PORT=3000
|
||||
METRICS_PORT=3001
|
||||
API_INSTANCES=1
|
||||
DATABASE_URL=postgresql://postgres:${config.sops.placeholder."panel/postgres-password"}@remnawave-db:5432/postgres
|
||||
REDIS_HOST=remnawave-valkey
|
||||
REDIS_PORT=6379
|
||||
APP_SECRET=${config.sops.placeholder."panel/app-secret"}
|
||||
IS_TELEGRAM_NOTIFICATIONS_ENABLED=false
|
||||
WEBHOOK_ENABLED=false
|
||||
FRONT_END_DOMAIN=${cfg.subdomain}.${domain}
|
||||
SUB_PUBLIC_DOMAIN=sub.${domain}
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
let
|
||||
cfg = config.vps.remnawave;
|
||||
in
|
||||
{
|
||||
imports = [ ./config.nix ];
|
||||
|
||||
config = mkIf (cfg.enable && cfg.type == "panel") {
|
||||
virtualisation.oci-containers.containers.remnapanel = {
|
||||
image = "docker.io/remnawave/backend:3.4.11";
|
||||
autoStart = true;
|
||||
environmentFiles = [ config.sops.templates."remnapanel.env".path ];
|
||||
ports = [ "127.0.0.1:3000:3000" ];
|
||||
log-driver = "journald";
|
||||
extraOptions = [
|
||||
"--network=remnawave"
|
||||
"--hostname=remnapanel"
|
||||
"--ulimit=nofile=1048576:1048576"
|
||||
];
|
||||
};
|
||||
|
||||
systemd.services.docker-remnawave-network = {
|
||||
description = "Create the remnawave docker network";
|
||||
after = [ "docker.service" ];
|
||||
requires = [ "docker.service" ];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
RemainAfterExit = true;
|
||||
};
|
||||
script = ''
|
||||
if ! ${pkgs.docker}/bin/docker network inspect remnawave >/dev/null 2>&1; then
|
||||
${pkgs.docker}/bin/docker network create remnawave
|
||||
fi
|
||||
'';
|
||||
};
|
||||
|
||||
systemd.services.docker-remnapanel = {
|
||||
after = [
|
||||
"docker-remnawave-network.service"
|
||||
"docker-remnawave-db.service"
|
||||
"docker-remnawave-valkey.service"
|
||||
"sops-nix.service"
|
||||
];
|
||||
requires = [
|
||||
"docker-remnawave-network.service"
|
||||
"docker-remnawave-db.service"
|
||||
"docker-remnawave-valkey.service"
|
||||
];
|
||||
wants = [ "sops-nix.service" ];
|
||||
serviceConfig.LimitNOFILE = 1048576;
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
let
|
||||
cfg = config.vps.remnawave;
|
||||
in
|
||||
{
|
||||
config = mkIf (cfg.enable && cfg.type == "panel") {
|
||||
sops.secrets."panel/subpage-api-token" = { };
|
||||
|
||||
sops.templates."remnawave-subpage.env" = {
|
||||
mode = "0400";
|
||||
content = ''
|
||||
REMNAWAVE_PANEL_URL=http://remnapanel:3000
|
||||
APP_PORT=3010
|
||||
TRUST_PROXY=1
|
||||
REMNAWAVE_API_TOKEN=${config.sops.placeholder."panel/subpage-api-token"}
|
||||
'';
|
||||
};
|
||||
|
||||
virtualisation.oci-containers.containers.remnawave-subpage = {
|
||||
image = "docker.io/remnawave/subscription-page:8.0.1";
|
||||
autoStart = true;
|
||||
environmentFiles = [ config.sops.templates."remnawave-subpage.env".path ];
|
||||
ports = [ "127.0.0.1:3010:3010" ];
|
||||
log-driver = "journald";
|
||||
extraOptions = [
|
||||
"--network=remnawave"
|
||||
"--hostname=remnawave-subpage"
|
||||
"--ulimit=nofile=1048576:1048576"
|
||||
];
|
||||
};
|
||||
|
||||
systemd.services.docker-remnawave-subpage = {
|
||||
after = [
|
||||
"docker-remnawave-network.service"
|
||||
"docker-remnapanel.service"
|
||||
"sops-nix.service"
|
||||
];
|
||||
requires = [ "docker-remnawave-network.service" ];
|
||||
wants = [
|
||||
"docker-remnapanel.service"
|
||||
"sops-nix.service"
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
let
|
||||
cfg = config.vps.remnawave;
|
||||
domain = config.sops.placeholder."domain";
|
||||
in
|
||||
{
|
||||
config = mkIf (cfg.enable && cfg.type == "panel") {
|
||||
sops.secrets = {
|
||||
"domain" = { };
|
||||
"panel/tinyauth-users" = { };
|
||||
};
|
||||
|
||||
sops.templates."tinyauth.env" = {
|
||||
mode = "0400";
|
||||
content = ''
|
||||
TINYAUTH_PORT=3002
|
||||
TINYAUTH_APP_URL=https://ta.${domain}
|
||||
TINYAUTH_USERS=${config.sops.placeholder."panel/tinyauth-users"}
|
||||
'';
|
||||
};
|
||||
|
||||
virtualisation.oci-containers.containers.tinyauth = {
|
||||
image = "ghcr.io/maposia/remnawave-tinyauth:v5";
|
||||
autoStart = true;
|
||||
environmentFiles = [ config.sops.templates."tinyauth.env".path ];
|
||||
ports = [ "127.0.0.1:3002:3002" ];
|
||||
volumes = [ "tinyauth-data:/data" ];
|
||||
log-driver = "journald";
|
||||
extraOptions = [
|
||||
"--network=remnawave"
|
||||
"--hostname=tinyauth"
|
||||
];
|
||||
};
|
||||
|
||||
systemd.services.docker-tinyauth = {
|
||||
after = [
|
||||
"docker-remnawave-network.service"
|
||||
"sops-nix.service"
|
||||
];
|
||||
requires = [ "docker-remnawave-network.service" ];
|
||||
wants = [ "sops-nix.service" ];
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
let
|
||||
cfg = config.vps.remnawave;
|
||||
in
|
||||
{
|
||||
config = mkIf (cfg.enable && cfg.type == "panel") {
|
||||
virtualisation.oci-containers.containers.remnawave-valkey = {
|
||||
image = "docker.io/valkey/valkey:9.0.0-alpine";
|
||||
autoStart = true;
|
||||
cmd = [
|
||||
"valkey-server"
|
||||
"--save"
|
||||
""
|
||||
"--appendonly"
|
||||
"no"
|
||||
"--maxmemory-policy"
|
||||
"noeviction"
|
||||
"--loglevel"
|
||||
"warning"
|
||||
];
|
||||
log-driver = "journald";
|
||||
extraOptions = [
|
||||
"--network=remnawave"
|
||||
"--hostname=remnawave-valkey"
|
||||
"--ulimit=nofile=1048576:1048576"
|
||||
];
|
||||
};
|
||||
|
||||
systemd.services.docker-remnawave-valkey = {
|
||||
after = [ "docker-remnawave-network.service" ];
|
||||
requires = [ "docker-remnawave-network.service" ];
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user