···
+
command = lib.mkOption {
+
type = lib.types.listOf lib.types.str;
+
Command to pass to --stdin-from-command. If null or an empty array, and `paths`/`dynamicFilesFrom`
+
are also null, no backup command will be run.
type = lib.types.listOf lib.types.str;
···
runCheck = lib.mkOption {
+
default = builtins.length config.services.restic.backups.${name}.checkOpts > 0;
defaultText = lib.literalExpression ''builtins.length config.services.backups.${name}.checkOpts > 0'';
description = "Whether to run the `check` command with the provided `checkOpts` options.";
···
RandomizedDelaySec = "5h";
+
"\${lib.getExe pkgs.sudo}"
+
"\${pkgs.postgresql}/bin/pg_dumpall"
+
extraBackupArgs = [ "--tag database" ];
+
repository = "s3:example.com/mybucket";
+
passwordFile = "/etc/nixos/secrets/restic-password";
+
environmentFile = "/etc/nixos/secrets/restic-environment";
+
assertions = lib.flatten (
+
lib.mapAttrsToList (name: backup: [
+
assertion = (backup.repository == null) != (backup.repositoryFile == null);
+
message = "services.restic.backups.${name}: exactly one of repository or repositoryFile should be set";
+
fileBackup = (backup.paths != null && backup.paths != [ ]) || backup.dynamicFilesFrom != null;
+
commandBackup = backup.command != [ ];
+
!(fileBackup && commandBackup);
+
message = "services.restic.backups.${name}: cannot do both a command backup and a file backup at the same time.";
+
]) config.services.restic.backups
systemd.services = lib.mapAttrs' (
···
) "--exclude-file=${pkgs.writeText "exclude-patterns" (lib.concatStringsSep "\n" backup.exclude)}";
filesFromTmpFile = "/run/restic-backups-${name}/includes";
+
fileBackup = (backup.dynamicFilesFrom != null) || (backup.paths != null && backup.paths != [ ]);
+
commandBackup = backup.command != [ ];
+
doBackup = fileBackup || commandBackup;
pruneCmd = lib.optionals (builtins.length backup.pruneOpts > 0) [
(resticCmd + " forget --prune " + (lib.concatStringsSep " " backup.pruneOpts))
···
+
lib.optionals doBackup [
+
lib.concatStringsSep " " (
+
++ lib.optionals fileBackup (excludeFlags ++ [ "--files-from=${filesFromTmpFile}" ])
+
++ lib.optionals commandBackup ([ "--stdin-from-command=true --" ] ++ backup.command)
···
${lib.optionalString (backup.backupPrepareCommand != null) ''
${pkgs.writeScript "backupPrepareCommand" backup.backupPrepareCommand}
+
${lib.optionalString backup.initialize ''
${resticCmd} cat config > /dev/null || ${resticCmd} init
${lib.optionalString (backup.paths != null && backup.paths != [ ]) ''
···
${lib.optionalString (backup.backupCleanupCommand != null) ''
${pkgs.writeScript "backupCleanupCommand" backup.backupCleanupCommand}
+
${lib.optionalString fileBackup ''
···
lib.nameValuePair "restic-backups-${name}" {
wantedBy = [ "timers.target" ];
+
inherit (backup) timerConfig;
) (lib.filterAttrs (_: backup: backup.timerConfig != null) config.services.restic.backups);
···
${lib.pipe config.systemd.services."restic-backups-${name}".environment [
(lib.filterAttrs (n: v: v != null && n != "PATH"))
(lib.mapAttrs (_: v: "${v}"))
PATH=${config.systemd.services."restic-backups-${name}".environment.PATH}:$PATH