diff --git a/backup.nix b/backup.nix index 6b11ba9..d21cafd 100644 --- a/backup.nix +++ b/backup.nix @@ -1,7 +1,6 @@ { lib, config, pkgs, utils, ... }: let cfg = config.backup-helper; - escaped-path = "/etc/machine-id"; restic-wrapper = pkgs.writeShellApplication { name = "restic-wrapper"; runtimeInputs = [ @@ -9,13 +8,13 @@ let pkgs.systemd ]; text = '' - if [ "$#" -ne 1 ]; then - echo "Need exactly one argument, the path to backup."; + if [ -z "$BACKUP_HELPER_DIRS" ]; then + echo "BACKUP_HELPER_DIRS is not set"; exit 1; fi - path="$1"; - echo "Starting backup of $path"; - # restic backup ${escaped-path}; + for i in ''${BACKUP_HELPER_DIRS//,/ }; do + echo "Starting backup of $i"; + done ''; }; in @@ -49,28 +48,26 @@ in }; }; config = lib.mkIf cfg.enable { - systemd.services."backup-helper@" = { + systemd.services."backup-helper" = { after = [ "network-online.target" ]; environment = { RESTIC_REPOSITORY = cfg.restic-repository; + BACKUP_HELPER_DIRS = lib.strings.concatStringsSep "," cfg.backup-dirs; } // lib.attrsets.optionalAttrs (builtins.hasAttr "password-file" cfg) { RESTIC_PASSWORD_FILE = cfg.password-file; }; serviceConfig = { Type = "oneshot"; - ExecStart = "${restic-wrapper}/bin/restic-wrapper %f"; + ExecStart = "${restic-wrapper}/bin/restic-wrapper"; }; }; - systemd.timers."backup-helper@" = { + systemd.timers."backup-helper" = { timerConfig = { OnCalendar = cfg.schedule; Persistent = true; RandomizedDelaySec = cfg.randomized-delay; }; - }; - systemd.timers.${escaped-path} = { wantedBy = [ "timers.target" ]; - overrideStrategy = "asDropin"; }; }; }