about summary refs log tree commit diff
path: root/nixos/modules/services/backup
diff options
context:
space:
mode:
authorAlvar Penning <post@0x21.biz>2023-03-11 12:23:24 +0100
committerAlvar Penning <post@0x21.biz>2023-03-11 12:59:10 +0100
commitadafbeff4ad01e21b9d1b39f072298978c08aa6c (patch)
tree6dbd73b8535dbad3661d1a6bb953ff32b3a3535f /nixos/modules/services/backup
parent898da5f74e4869af867b2e5cb1ff06202aecd910 (diff)
downloadnixlib-adafbeff4ad01e21b9d1b39f072298978c08aa6c.tar
nixlib-adafbeff4ad01e21b9d1b39f072298978c08aa6c.tar.gz
nixlib-adafbeff4ad01e21b9d1b39f072298978c08aa6c.tar.bz2
nixlib-adafbeff4ad01e21b9d1b39f072298978c08aa6c.tar.lz
nixlib-adafbeff4ad01e21b9d1b39f072298978c08aa6c.tar.xz
nixlib-adafbeff4ad01e21b9d1b39f072298978c08aa6c.tar.zst
nixlib-adafbeff4ad01e21b9d1b39f072298978c08aa6c.zip
nixos/restic: generalize cache configuration
The restic repository cache location defaults to ~/.cache/restic when
not overwritten either by the --cache-dir command line parameter or the
universal RESTIC_CACHE_DIR environment variable.

Currently, the --cache-dir variable is set to only some restic commands,
but, e.g., not to the unit's preStart command for the module's
initialize option. This results in two distinct cache locations, one at
~/.cache/restic for the initialize commands and one at the configured
--cache-dir location for the restic backup command.

By explicitly setting RESTIC_CACHE_DIR for the unit, only one cache at
the correct location will be used.

https://restic.readthedocs.io/en/v0.15.1/manual_rest.html#caching
Diffstat (limited to 'nixos/modules/services/backup')
-rw-r--r--nixos/modules/services/backup/restic.nix7
1 files changed, 4 insertions, 3 deletions
diff --git a/nixos/modules/services/backup/restic.nix b/nixos/modules/services/backup/restic.nix
index bc24e13aa050..ca796cf7797e 100644
--- a/nixos/modules/services/backup/restic.nix
+++ b/nixos/modules/services/backup/restic.nix
@@ -303,8 +303,8 @@ in
               then if (backup.paths != null) then concatStringsSep " " backup.paths else ""
               else "--files-from ${filesFromTmpFile}";
             pruneCmd = optionals (builtins.length backup.pruneOpts > 0) [
-              (resticCmd + " forget --prune --cache-dir=%C/restic-backups-${name} " + (concatStringsSep " " backup.pruneOpts))
-              (resticCmd + " check --cache-dir=%C/restic-backups-${name} " + (concatStringsSep " " backup.checkOpts))
+              (resticCmd + " forget --prune " + (concatStringsSep " " backup.pruneOpts))
+              (resticCmd + " check " + (concatStringsSep " " backup.checkOpts))
             ];
             # Helper functions for rclone remotes
             rcloneRemoteName = builtins.elemAt (splitString ":" backup.repository) 1;
@@ -314,6 +314,7 @@ in
           in
           nameValuePair "restic-backups-${name}" ({
             environment = {
+              RESTIC_CACHE_DIR = "%C/restic-backups-${name}";
               RESTIC_PASSWORD_FILE = backup.passwordFile;
               RESTIC_REPOSITORY = backup.repository;
               RESTIC_REPOSITORY_FILE = backup.repositoryFile;
@@ -332,7 +333,7 @@ in
             restartIfChanged = false;
             serviceConfig = {
               Type = "oneshot";
-              ExecStart = (optionals (backupPaths != "") [ "${resticCmd} backup --cache-dir=%C/restic-backups-${name} ${concatStringsSep " " (backup.extraBackupArgs ++ excludeFlags)} ${backupPaths}" ])
+              ExecStart = (optionals (backupPaths != "") [ "${resticCmd} backup ${concatStringsSep " " (backup.extraBackupArgs ++ excludeFlags)} ${backupPaths}" ])
                 ++ pruneCmd;
               User = backup.user;
               RuntimeDirectory = "restic-backups-${name}";