nixcfg/hosts/mauville/home.nix
Aly Raffauf 67d0f7f6ac
mauville: idempotent backblaze authentication (#37)
* mauville: add backblaze secrets

* mauville/home: authenticate with backblaze before nightly backups

* fix format

* mauville: move backblaze secret to home

* aly: setup backblaze secrets

* mauville: pass config to hm module
2024-07-15 23:53:15 -04:00

69 lines
1.9 KiB
Nix

{
config,
lib,
pkgs,
self,
...
}: {
home-manager = {
sharedModules = [
{
xdg.userDirs.music = "/mnt/Media/Music";
ar.home.desktop.hyprland = {
autoSuspend = false;
monitors = ["desc:LG Electronics LG ULTRAWIDE 311NTAB5M720,preferred,auto,1.25,vrr,2"];
};
}
];
users.aly = lib.mkForce ({
config,
pkgs,
lib,
...
}: {
imports = [self.homeManagerModules.aly];
systemd.user = {
services.backblaze-sync = {
Unit.Description = "Backup to Backblaze.";
Service.ExecStart = "${pkgs.writeShellScript "backblaze-sync" ''
# Authenticate with backblaze.
b2KeyId=`cat ${config.age.secrets.backblazeKeyId.path}`
b2Key=`cat ${config.age.secrets.backblazeKey.path}`
${lib.getExe pkgs.backblaze-b2} authorize_account $b2KeyId $b2Key
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
''}";
};
timers.backblaze-sync = {
Install.WantedBy = ["timers.target"];
Timer.OnCalendar = "*-*-* 03:00:00";
Unit.Description = "Daily backups to Backblaze.";
};
};
});
};
}