ctucx.git: nixfiles

ctucx' nixfiles

commit 409b59dfda1e588be40461f04917a6252f115273
parent 51aebfb2c5baa0a4edc8e273d1cc17afacb2ad83
Author: Leah (ctucx) <leah@ctu.cx>
Date: Thu, 3 Feb 2022 14:20:53 +0100

modules/restic-backup: add `targets` option
1 file changed, 17 insertions(+), 5 deletions(-)
M
modules/restic-backups.nix
|
22
+++++++++++++++++-----
diff --git a/modules/restic-backups.nix b/modules/restic-backups.nix
@@ -27,6 +27,11 @@ let
         default = [];
       };
 
+      targets = mkOption {
+        type    = with types; listOf str;
+        default = [ "desastro.ctu.cx" "lollo.ctu.cx" "hector.ctu.cx" ];
+      };
+
       timerConfig = mkOption {
         type    = types.attrs;
         default = {

@@ -38,8 +43,6 @@ let
     };
   };
 
-  servers = [ "desastro.ctu.cx" "lollo.ctu.cx" ];
-
 in {
 
   options.restic-backups = mkOption {

@@ -80,8 +83,17 @@ in {
                 set -eu pipefail
 
                 cp ${backup.passwordFile} /tmp/passwordFile;
-                cp /run/agenix/restic-server-lollo    /tmp/lollo.ctu.cx;
-                cp /run/agenix/restic-server-desastro /tmp/desastro.ctu.cx;
+                ${if builtins.elem "lollo.ctu.cx" backup.targets then ''
+                  cp /run/agenix/restic-server-lollo    /tmp/lollo.ctu.cx;
+                '' else "" }
+
+                ${if builtins.elem "desastro.ctu.cx" backup.targets then ''
+                  cp /run/agenix/restic-server-desastro /tmp/desastro.ctu.cx;
+                '' else "" }
+
+                ${if builtins.elem "hector.ctu.cx" backup.targets then ''
+                  cp /run/agenix/restic-server-hector   /tmp/hector.ctu.cx;
+                '' else "" }
 
                 chown -R ${backup.user} /tmp
               ''))

@@ -117,7 +129,7 @@ in {
           restic backup ${concatStringsSep " " (backup.paths ++ optional (backup.postgresDatabases != []) "/tmp/postgresDatabases") }
 
           restic check
-        '') servers;
+        '') backup.targets;
 
       }
     ) backups;