nixos-config/services/restic/home-pc.nix

115 lines
3.4 KiB
Nix
Raw Normal View History

2022-01-27 15:01:24 +01:00
{ config, lib, pkgs, ... }:
# using the restic cli:
2022-05-09 12:26:12 +02:00
# load credentials into shell by adding B2 secrets to .env (see .env.example).
2022-01-27 15:01:24 +01:00
# useful commands for analysing restic stats [snapshot-id], restic diff [s1] [s2],
with lib;
with builtins;
let resticLib = import ./lib.nix { inherit config lib pkgs; };
2022-01-27 15:01:24 +01:00
in {
imports = [ ./common.nix ];
2022-01-27 15:01:24 +01:00
environment.systemPackages = with pkgs; [ restic ];
services.restic.backups.full = resticLib.resticConfig {
2022-01-27 15:01:24 +01:00
name = "home-pc";
paths = [ "/etc/nixos" "/var/lib" "/home" ];
2022-08-15 21:05:58 +02:00
# inspiration: https://github.com/rubo77/rsync-homedir-excludes
ignorePatterns = [
"/var/lib/systemd"
2022-07-04 17:11:44 +02:00
"/var/lib/libvirt"
"/var/lib/containers"
2022-08-12 12:30:01 +02:00
"/var/lib/nixos-containers"
"/var/lib/lxcfs"
"/var/lib/docker"
"/var/lib/flatpak"
"/home/*/Downloads"
2022-08-15 21:05:58 +02:00
"/home/*/Pictures"
"/home/*/Videos"
"/home/*/Music"
"/home/*/Games"
2022-08-15 21:05:58 +02:00
"/home/*/.android"
"/home/*/.AndroidStudio*"
2022-07-04 17:11:44 +02:00
"/home/*/.cache"
"/home/*/.cargo"
2022-08-15 21:05:58 +02:00
"/home/*/.compose-cache"
"/home/*/.dotnet"
"/home/*/.gradle"
"/home/*/.mozilla"
2023-04-13 14:30:57 +02:00
"/home/*/.mullvad"
2022-07-04 17:11:44 +02:00
"/home/*/.npm"
"/home/*/.nuget"
2022-08-15 21:05:58 +02:00
"/home/*/.rustup"
"/home/*/.steam"
2022-08-15 21:05:58 +02:00
"/home/*/.templateengine"
"/home/*/.var"
2022-08-15 21:05:58 +02:00
"/home/*/.wine"
2022-07-04 17:11:44 +02:00
"/home/*/.local/share/containers"
"/home/*/.local/share/docker"
"/home/*/.local/share/flatpak"
2022-07-04 17:11:44 +02:00
"/home/*/.local/share/bottles"
"/home/*/.local/share/Steam"
2022-08-15 21:05:58 +02:00
"/home/*/.local/share/keybase"
"/home/*/.local/share/libvirt"
"/home/*/.local/share/lutris"
2022-07-04 17:11:44 +02:00
"/home/*/.local/share/NuGet"
2022-08-15 21:05:58 +02:00
"/home/*/.local/share/tor-browser"
2022-09-04 11:24:05 +02:00
"/home/*/.local/share/com.github.johnfactotum.Foliate/books"
2022-08-15 21:05:58 +02:00
"/home/*/.local/share/Trash"
"/home/*/.config/BraveSoftware"
"/home/*/.config/chromium"
"/home/*/.config/gatsby"
2022-09-28 15:33:18 +02:00
"/home/*/.config/heroic"
2022-07-04 17:11:44 +02:00
"/home/*/.config/libvirt"
2022-08-15 21:05:58 +02:00
"/home/*/.config/spotify/Users"
"/home/felschr/media"
"/home/felschr/keybase"
"/home/felschr/dev" # backup ~/dev-backup instead
2022-08-15 21:05:58 +02:00
# general
".cache"
"cache"
".tmp"
".temp"
"tmp"
"temp"
".log"
"log"
".Trash"
# electron apps
"/home/*/.config/**/blob_storage"
"/home/*/.config/**/Application Cache"
"/home/*/.config/**/Cache"
"/home/*/.config/**/CachedData"
"/home/*/.config/**/Code Cache"
"/home/*/.config/**/GPUCache"
"/home/*/.var/app/**/blob_storage"
"/home/*/.var/app/**/Application Cache"
"/home/*/.var/app/**/Cache"
"/home/*/.var/app/**/CachedData"
"/home/*/.var/app/**/Code Cache"
"/home/*/.var/app/**/GPUCache"
];
timerConfig.OnCalendar = "0/6:00:00";
extraPruneOpts = [ "--keep-last 4" ];
2022-01-27 15:01:24 +01:00
};
# Extra handling for dev folder to respect .gitignore files.
# Do not delete `~/dev-backup` since this leads to changing ctimes
# which would cause otherwise unchanged files to be backed up again.
# Since `--link-dest` is used, file contents won't be duplicated on disk.
systemd.services."restic-backups-full" = {
preStart = ''
rm -rf /home/felschr/dev-backup
${pkgs.rsync}/bin/rsync \
-a --delete \
--filter=':- .gitignore' \
--exclude 'nixpkgs' \
--link-dest=/home/felschr/dev \
/home/felschr/dev/ /home/felschr/dev-backup
'';
};
2022-01-27 15:01:24 +01:00
}