2025-01-17 20:19:21 +01:00

25 lines
762 B
Nix

{pkgs, ...}:
{
# Add a udev rule that launches a backup using restic when a specific USB device (the backup drive) is plugged in
environment.systemPackages = with pkgs; [
restic
];
# the udev rule:
services.udev.extraRules = ''
ACTION=="add", SUBSYSTEM=="block", ENV{ID_FS_LABEL}=="backup-restic", TAG+="systemd", ENV{SYSTEMD_WANTS}="backup-restic.service"
'';
# the systemd service:
systemd.services.backup-restic = {
description = "Backup using restic (triggered when USB drive is plugged in)";
after = [ "local-fs.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "oneshot";
# TODO: adapt command
ExecStart = "${pkgs.restic}/bin/restic backup /home/username";
};
};
}