From 5637febfd5f8b27568c32a76e55702e29675f63a Mon Sep 17 00:00:00 2001 From: Anish L Date: Tue, 14 Jun 2022 15:23:09 +1000 Subject: [PATCH] added backup module and backups for box and curve also put a reverse proxy infront of radicale --- hosts/box/default.nix | 19 ++++++++++++ hosts/curve/default.nix | 22 ++++++++------ modules/backup.nix | 54 +++++++++++++++++++++++++++++++++++ profiles/radicale/default.nix | 13 +++++++++ 4 files changed, 100 insertions(+), 8 deletions(-) create mode 100644 modules/backup.nix diff --git a/hosts/box/default.nix b/hosts/box/default.nix index ada393dd..c2ac2a65 100644 --- a/hosts/box/default.nix +++ b/hosts/box/default.nix @@ -12,4 +12,23 @@ services."grasp".enable = true; services."grasp".path = "/home/anish/kitaab/grasp"; services."grasp".user = "anish"; + + services.postgresqlBackup = { + enable = true; + databases = [ "wallabag" ]; + location = "/var/backup/postgresql"; + }; + + mossnet.backup = { + enable = true; + name = "mossnet"; + paths = [ + "/var/lib/taskserver" # taskwarrior + "/var/www/shaarli-config" # sharli + "/var/backup/postgresql" # wallabag + "/var/lib/radicale" # radicale + ]; + # seafile? + # syncthing + }; } diff --git a/hosts/curve/default.nix b/hosts/curve/default.nix index 436519e5..13e51aa3 100644 --- a/hosts/curve/default.nix +++ b/hosts/curve/default.nix @@ -28,22 +28,28 @@ boot.supportedFilesystems = [ "ntfs" ]; + mossnet.backup = { + enable = true; + name = "curve"; + paths = [ "/home/anish" ]; + }; + # enable adb # TODO move this (it's for KaiOS WebIDE devShell?) programs.adb.enable = true; #virtualisation.docker.enable = true; services.udev.extraRules = '' - # Monitor plugged in - # Doesn't work, becuase /home/anish/bin/hotplug-monitor isn't part of the nix build - # KERNEL=="card0", SUBSYSTEM=="drm", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/anish/.Xauthority", RUN+="/home/anish/bin/hotplug-monitor.sh" # TODO: add this file to nix home-manager + # Monitor plugged in + # Doesn't work, becuase /home/anish/bin/hotplug-monitor isn't part of the nix build + # KERNEL=="card0", SUBSYSTEM=="drm", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/anish/.Xauthority", RUN+="/home/anish/bin/hotplug-monitor.sh" # TODO: add this file to nix home-manager - # Qualcomm EDL - SUBSYSTEMS=="usb", ATTRS{idVendor}=="05c6", ATTRS{idProduct}=="9008", MODE="0666", GROUP="plugdev" + # Qualcomm EDL + SUBSYSTEMS=="usb", ATTRS{idVendor}=="05c6", ATTRS{idProduct}=="9008", MODE="0666", GROUP="plugdev" - # Qualcomm Memory Debug - SUBSYSTEMS=="usb", ATTRS{idVendor}=="05c6", ATTRS{idProduct}=="9006", MODE="0666", GROUP="plugdev" + # Qualcomm Memory Debug + SUBSYSTEMS=="usb", ATTRS{idVendor}=="05c6", ATTRS{idProduct}=="9006", MODE="0666", GROUP="plugdev" - # Atmel DFU + # Atmel DFU ### ATmega16U2 SUBSYSTEMS=="usb", ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2fef", TAG+="uaccess" ### ATmega32U2 diff --git a/modules/backup.nix b/modules/backup.nix new file mode 100644 index 00000000..eabdc1b3 --- /dev/null +++ b/modules/backup.nix @@ -0,0 +1,54 @@ +# Assumes the remote borg backup server has already been initialized +# TODO: +# This currently works on a per host basis, and the host file has to define all the locations it wants to back up. +# Ideally, this would create a job for each profile instead, so the backup strategy is included in the profile regardless of host +{ config, lib, pkgs, ... }: +with lib; +let + cfg = config.mossnet.backup; +in +{ + options = { + mossnet.backup = { + enable = mkEnableOption "Backup module using borg for Anish's computer nursery"; + name = lib.mkOption { + type = types.str; + default = { }; + example = literalExample '' + shaarli + ''; + description = '' + name for the backup operator + ''; + }; + paths = lib.mkOption { + type = with types; attrsOf (listOf str); + default = { }; + example = literalExample '' + [ "/home/anish/usr" ]; + ''; + description = '' + A list of folders to backup + ''; + }; + }; + }; + + config = mkIf cfg.enable { + services.borgbackup.jobs = { + "${cfg.name}" = { + paths = cfg.paths; + doInit = true; + repo = "20779@hk-s020.rsync.net:${cfg.name}"; + encryption = { + mode = "repokey-blake2"; + passCommand = "cat /run/keys/borg-password"; + }; + environment = { BORG_RSH = "ssh -i /root/borg/borg-key"; }; # YOU NEED TO PUT THIS HERE MANUALLY + compression = "auto,lzma"; + startAt = "weekly"; + extraArgs = "--remote-path=borg1"; + }; + }; + }; +} diff --git a/profiles/radicale/default.nix b/profiles/radicale/default.nix index 9604acd6..e08af459 100644 --- a/profiles/radicale/default.nix +++ b/profiles/radicale/default.nix @@ -7,5 +7,18 @@ server.hosts = [ "0.0.0.0:5252" ]; }; }; + networking.firewall.allowedTCPPorts = [ 5252 ]; + + services.nginx.virtualHosts."cal.mossnet.lan" = { + enableACME = false; + forceSSL = false; + + locations."/" = { + extraConfig = '' + proxy_pass http://localhost:5252/; + proxy_set_header X-Forwarded-Host $host; + ''; + }; + }; }