]> Git — Sourcephile - julm/julm-nix.git/blob - hosts/patate/backup/rsync-backup.nix
nftables: polish
[julm/julm-nix.git] / hosts / patate / backup / rsync-backup.nix
1 { pkgs, lib, config, hostName, ... }:
2 with builtins;
3 {
4 home-manager.users.sevy = {
5 systemd.user.services."rsync-term@" = {
6 Unit = {
7 Description = "rsync terminal for: %I";
8 After = [ "graphical-session.target" ];
9 StopWhenUnneeded = false;
10 };
11 Service = {
12 Type = "simple";
13 ExecStart = pkgs.writeShellScript "rsync-term" ''
14 FS_LABEL=$1
15 set -eux
16 ${pkgs.xterm}/bin/xterm -fg white -bg black -fa Monospace -fs 6 \
17 -title "rsync backup to: $FS_LABEL" -e "journalctl --user -f -o short \
18 -u rsync-backup@$FS_LABEL"
19 '' + " %I";
20 };
21 };
22 systemd.user.services."rsync-backup@" = {
23 Unit = {
24 Description = "rsync backup: %i";
25 Wants = [ "rsync-term@%i.service" ];
26 BindsTo = [ "sys-subsystem-usb-%i.device" ];
27 };
28 Service = {
29 Type = "oneshot";
30 SyslogIdentifier = "rsync-backup@%i";
31 ExecStart = pkgs.writeShellScript "rsync-backup" ''
32 FS_LABEL=$1
33 set -eux
34 # FIXME: utillinux -> unit-linux when updating to 20.05
35 DEVICE=$(${pkgs.utillinux}/bin/blkid -l -o device -t LABEL="$FS_LABEL")
36 while ! ${pkgs.glib}/bin/gio mount --device "$DEVICE"
37 do test ! -d /run/media/sevy/"$FS_LABEL" || break
38 sleep 1
39 done
40 ${pkgs.rsync}/bin/rsync --verbose --itemize-changes \
41 --partial --recursive --times \
42 --compress-level=0 --delete --delete-before \
43 /run/media/sevy/"$FS_LABEL" \
44 ~sevy/Documents/
45 systemctl --user --no-block stop rsync-term@"$FS_LABEL"
46 '' + " %I";
47 };
48 };
49 };
50 }