Init
Initial commit, nodes are mostly done, panel is WIP
This commit is contained in:
commit
6761a7c440
73 files changed
+3413
No files matched your search
@@ -0,0 +1,23 @@
|
||||
{ config, lib, ... }:
|
||||
with lib;
|
||||
let
|
||||
rootCfg = config.vps.remnawave;
|
||||
in
|
||||
{
|
||||
config = mkIf (rootCfg.panel.backup.enable && rootCfg.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".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"}
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
let
|
||||
rootCfg = config.vps.remnawave;
|
||||
in
|
||||
{
|
||||
imports = [ ./config.nix ];
|
||||
|
||||
options.vps.remnawave.panel.backup = {
|
||||
enable = mkEnableOption "Enable panel backups";
|
||||
};
|
||||
|
||||
config = mkIf (rootCfg.panel.backup.enable && rootCfg.type == "panel") {
|
||||
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 = 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
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
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 -" ];
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user