Skip to content

Commit 2811124

Browse files
committed
marie-desktop: add restic backup service
1 parent bdc224c commit 2811124

File tree

5 files changed

+96
-0
lines changed

5 files changed

+96
-0
lines changed

hosts/marie-desktop/backup.nix

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{ pkgs, config, lib, ... }:
2+
{
3+
age.secrets.restic-password = {
4+
file = ./secrets/restic-password.age;
5+
owner = "marie";
6+
group = "users";
7+
};
8+
systemd.services.backup = {
9+
after = [ "network-online.target" ];
10+
wants = [ "network-online.target" ];
11+
serviceConfig = {
12+
PrivateMounts = true;
13+
SystemCallFilter = [ "@system-service" "@mount" ];
14+
};
15+
environment = {
16+
RESTIC_REPOSITORY = "sftp:marie@marie-nas.fritz.box:/srv/restic/marie";
17+
RESTIC_PASSWORD_FILE = config.age.secrets.restic-password.path;
18+
SSH_AUTH_SOCK = "/run/user/1000/ssh-agent";
19+
HOME = "/home/marie";
20+
};
21+
path = with pkgs; [ restic util-linux btrfs-progs config.programs.ssh.package config.security.sudo.package ];
22+
script = ''
23+
set -euo pipefail
24+
SNAPSHOT_NAME="@restic-$(date "+%F_%k-%M-%S")"
25+
btrfs subvolume snapshot /home "/home/$SNAPSHOT_NAME"
26+
27+
function cleanup() {
28+
mount -t btrfs -o subvol=home ${config.fileSystems."/home".device} /home
29+
btrfs subvolume delete "/home/$SNAPSHOT_NAME"
30+
}
31+
32+
trap cleanup EXIT
33+
34+
umount /home
35+
mount -t btrfs -o subvol="/home/$SNAPSHOT_NAME" '${config.fileSystems."/home".device}' /home
36+
37+
sudo \
38+
--user=marie \
39+
--preserve-env=RESTIC_REPOSITORY,RESTIC_PASSWORD_FILE,SSH_AUTH_SOCK \
40+
restic backup \
41+
--exclude-caches \
42+
--exclude-file "${./scripts/restic-excludes.txt}" \
43+
--tag home \
44+
--one-file-system \
45+
"$HOME"
46+
'';
47+
};
48+
}

hosts/marie-desktop/configuration.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
{
33
imports = with inputs; [
44
home-manager-unstable.nixosModules.default
5+
agenix.nixosModules.default
56
./hardware.nix
67
./gaming.nix
78
./suspend-fix.nix
89
./tailscale.nix
910
./syncthing.nix
1011
./wireshark.nix
12+
./backup.nix
1113
];
1214

1315
uwumarie.profiles = {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
$HOME/**/Cache
2+
$HOME/**/Caches
3+
$HOME/**/cache
4+
$HOME/**/caches
5+
$HOME/**/.cache
6+
$HOME/**/__pycache__
7+
8+
$HOME/.config/*/Cache
9+
$HOME/.config/*/GPUCache
10+
$HOME/.config/*/ShaderCache
11+
$HOME/.config/*/DawnCache
12+
$HOME/.config/*/DawnGraphiteCache
13+
$HOME/.config/*/DawnWebGPUCache
14+
15+
$HOME/.config/VSCodium/CachedData
16+
$HOME/.config/VSCodium/CachedExtensions
17+
$HOME/.config/VSCodium/logs
18+
19+
$HOME/.local/share/Steam
20+
$HOME/.local/share/pnpm
21+
$HOME/.local/share/containers
22+
$HOME/.local/share/umu
23+
24+
$HOME/.rustup
25+
$HOME/.yarn
26+
$HOME/.npm
27+
$HOME/.jdks
28+
$HOME/.cargo
29+
$HOME/.compose-cache
30+
$HOME/.ccache
31+
$HOME/.android
32+
$HOME/.gradle
33+
34+
$HOME/.var/app/com.usebottles.bottles
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
age-encryption.org/v1
2+
-> ssh-ed25519 GkDrBg hlklf6O6XbDOm1t42koXo3lqCyhk6vfkKVEmS8VRWwo
3+
AwRFsyGEo2GvLaR3dxqBWs5LtEZN3BeVz/Phr5HRsIk
4+
-> ssh-ed25519 /tLDqA kC/Sxf9S1/3uUoY5XfEsfA1+52s+EgToc/ktAyWdwz8
5+
1nI4VDwqmrgNDf/GxFDqFJIoKipSzO9MNwW9t3VNxqs
6+
-> ssh-ed25519 kl9Tcw 0rZ7RBdPuMItattk4JIrchPakWp8JWojFHWHLVy9Im8
7+
qBPidAlVVxbKSm9bW2/PdsmdahZ76IKBWjX+a2XtDss
8+
--- ZJMS3G8LpYfS6t68+lkK19DmR4XvKLecHSx6QT27p+A
9+
i����:�v�V�i�ៗ�1���n����^�*��\p�@i�-@?�V6�dM�e@ن��(�����h�u�� �*2}�K�N0�

secrets/secrets.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ let
99
wsl = ["ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEpKCSJGPFfckgr1/X1Rv7jeOe9E8tYmP1iqogzSXF+u"];
1010
gitlabber = ["ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBFxL7AqowWxKzJqrj8Mr2MDF3NDbyExAPwKjohoCx/t"];
1111
marie-nas = ["ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILwvQy3cK9gGwFEf5UGCxQ61j8Kv30JDAZ39FOtKkrCQ"];
12+
marie-desktop-host = ["ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPSpnu/du04AEB2LuwIHJU5CZwBFsMLWUhNgn0+9tlte root@marie-desktop"];
1213
allSystems = artemis ++ delphi ++ wsl ++ marie-nas;
1314
users = marie-desktop-wsl ++ marie-desktop;
1415
in
@@ -42,4 +43,6 @@ in
4243
"../hosts/gitlabber/cachix-auth-token.age".publicKeys = users ++ gitlabber;
4344
"../hosts/gitlabber/forgejo-runner.age".publicKeys = users ++ gitlabber;
4445
"../hosts/artemis/applications/hedgedoc/env.age".publicKeys = users ++ artemis;
46+
47+
"../hosts/marie-desktop/secrets/restic-password.age".publicKeys = marie-desktop ++ marie-desktop-host;
4548
}

0 commit comments

Comments
 (0)