Stop using instanced service

This commit is contained in:
Torjus Håkestad 2024-06-02 23:41:37 +02:00
parent 012f28eb1e
commit 72a5468cb1

View File

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