mauville/home: build select flake nixosConfigurations daily

This commit is contained in:
Aly Raffauf 2024-06-17 22:51:27 -04:00
parent ade653b20d
commit 69544be359

View file

@ -66,41 +66,77 @@
users.aly = { users.aly = {
imports = [../../homes/aly.nix]; imports = [../../homes/aly.nix];
systemd.user = { systemd.user = {
services.backblaze-sync = { services = {
Unit = { backblaze-sync = {
Description = "Backup to Backblaze."; Unit = {
Description = "Backup to Backblaze.";
};
Service = {
ExecStart = "${pkgs.writeShellScript "backblaze-sync" ''
declare -A backups
backups=(
['/home/aly/pics/camera']="b2://aly-camera"
['/home/aly/sync']="b2://aly-sync"
['/mnt/Archive/Archive']="b2://aly-archive"
['/mnt/Media/Audiobooks']="b2://aly-audiobooks"
['/mnt/Media/Music']="b2://aly-music"
)
# Recursively backup folders to B2 with sanity checks.
for folder in "''${!backups[@]}"; do
if [ -d "$folder" ] && [ "$(ls -A "$folder")" ]; then
${lib.getExe pkgs.backblaze-b2} sync --delete $folder ''${backups[$folder]}
else
echo "$folder does not exist or is empty."
exit 1
fi
done
''}";
};
}; };
Service = {
ExecStart = "${pkgs.writeShellScript "backblaze-sync" '' build-hosts = {
declare -A backups Unit = {
backups=( Description = "Build nixosConfiguration for each host.";
['/home/aly/pics/camera']="b2://aly-camera" };
['/home/aly/sync']="b2://aly-sync" Service = {
['/mnt/Archive/Archive']="b2://aly-archive" ExecStart = "${pkgs.writeShellScript "build-hosts" ''
['/mnt/Media/Audiobooks']="b2://aly-audiobooks" hosts=(
['/mnt/Media/Music']="b2://aly-music" fallarbor
) lavaridge
# Recursively backup folders to B2 with sanity checks. petalburg
for folder in "''${!backups[@]}"; do rustboro
if [ -d "$folder" ] && [ "$(ls -A "$folder")" ]; then )
${lib.getExe pkgs.backblaze-b2} sync --delete $folder ''${backups[$folder]}
else for h in "''${hosts[@]}"; do
echo "$folder does not exist or is empty." nix build github:alyraffauf/nixcfg#nixosConfigurations.$h.config.system.build.toplevel
exit 1 done
fi ''}";
done };
''}";
}; };
}; };
timers.backblaze-sync = {
Unit = { timers = {
Description = "Daily backups to Backblaze."; backblaze-sync = {
Unit = {
Description = "Daily backups to Backblaze.";
};
Install = {
WantedBy = ["timers.target"];
};
Timer = {
OnCalendar = "*-*-* 03:00:00";
};
}; };
Install = { build-hosts = {
WantedBy = ["timers.target"]; Unit = {
}; Description = "Build hosts daily.";
Timer = { };
OnCalendar = "*-*-* 03:00:00"; Install = {
WantedBy = ["timers.target"];
};
Timer = {
OnCalendar = "*-*-* 06:00:00";
};
}; };
}; };
}; };