Skip to content

Instantly share code, notes, and snippets.

@Janik-Haag
Created September 22, 2023 06:59
Show Gist options
  • Save Janik-Haag/dc12b7284252cbc237ff2cef163e681d to your computer and use it in GitHub Desktop.
Save Janik-Haag/dc12b7284252cbc237ff2cef163e681d to your computer and use it in GitHub Desktop.
A NixOS restic configuration for automatic backups across multiple devices without extra configuration
{ inputs, config, ... }:
{
sops.secrets = let sopsFile = "${inputs.self}/secrets/shared.yaml"; in {
"backup/ssh-key" = {
sopsFile = sopsFile;
};
"backup/password" = {
sopsFile = sopsFile;
};
};
programs.ssh = {
extraConfig = ''
Host shared-storage.example.com
HostName shared-storage.example.com
IdentityFile ${config.sops.secrets."backup/ssh-key".path}
'';
knownHosts = {
"[sftp.shared-storage.example.com]:2828".publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAII7kuvjambYERPlPWa8ntvdyhvJbgO+rE7U3Lj1+CKh8";
};
};
services.restic.backups."${config.networking.hostName}" = {
user = "root";
timerConfig = {
OnCalendar = "daily";
Persistent = true;
};
repository = "sftp://janik@[shared-storage.example.com]:2828//backup";
passwordFile = config.sops.secrets."backup/password".path;
#pruneOpts = [ ];
paths = [
"/home"
"/root"
"/var/backup"
"/var/lib"
];
exclude = [
"/home/*/.cache"
"*Cache/Cache_Data*"
"*/share/containers/storage/*"
];
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment