Parameterise restic

restic-rest-server
Simon Bruder 2020-12-05 14:19:34 +01:00
parent 6d0f3a9964
commit 8a63f8aac4
No known key found for this signature in database
GPG Key ID: 6F03E0000CC5B62F
4 changed files with 51 additions and 28 deletions

View File

@ -6,7 +6,6 @@
./hardware-configuration.nix
../../modules/cpu/intel.nix
../../modules/gpu/intel.nix
../../modules/restic.nix
../../modules/ssd.nix
../../modules/libvirt.nix
../../modules
@ -16,6 +15,7 @@
sbruder = {
gui = true;
restic.enable = true;
};
boot.loader.grub.device = "/dev/disk/by-id/ata-INTEL_SSDSC2KB480G7_PHYS749202D6480BGN";

View File

@ -7,7 +7,6 @@
../../modules/cpu/intel.nix
../../modules/gpu/amd.nix
../../modules/libvirt.nix
../../modules/restic.nix
../../modules/ssd.nix
../../modules
../../profiles/dev.nix
@ -16,6 +15,7 @@
sbruder = {
gui = true;
restic.enable = true;
};
boot.loader.grub.device = "/dev/disk/by-id/ata-MTFDDAK256TBN-1AR15ABHA_UFZMQ01ZR50NMM";

View File

@ -21,6 +21,7 @@
./office.nix
./prometheus/node_exporter.nix
./pulseaudio.nix
./restic.nix
./ssh.nix
./sway.nix
./tools.nix

View File

@ -1,5 +1,7 @@
{ pkgs, config, lib, ... }:
{ pkgs, config, lib, options, ... }:
let
cfg = config.sbruder.restic;
name = "${config.networking.hostName}-system";
excludes = [
# General
@ -44,32 +46,52 @@ let
maybePath = path: (lib.optional (builtins.pathExists path) (toString path));
in
{
services.restic.backups."${name}" = {
passwordFile = toString (../secrets/restic_password);
s3CredentialsFile = toString ../secrets/s3_credentials;
repository = "s3:https://s3.eu-central-1.wasabisys.com/sbruder-restic";
paths = lib.mkDefault (
[ ]
++ maybePath /data
++ maybePath /home
++ maybePath /srv
++ maybePath /var
);
initialize = true;
extraBackupArgs = [
"--exclude-caches"
"--exclude-file=${excludesFile}"
"--verbose"
];
timerConfig = {
OnCalendar = "20:00";
RandomizedDelaySec = "2h";
};
options.sbruder.restic = {
enable = lib.mkEnableOption "restic";
timerConfig =
lib.recursiveUpdate
(
(builtins.elemAt
(builtins.elemAt
options.services.restic.backups.type.getSubModules
0
).imports
0)
{ name = ""; }
).options.timerConfig
{
default = {
OnCalendar = "20:00";
RandomizedDelaySec = "2h";
};
};
};
systemd.services."restic-backups-${name}".serviceConfig = {
"Nice" = 10;
"IOSchedulingClass" = "best-effort";
"IOSchedulingPriority" = 7;
config = lib.mkIf cfg.enable {
services.restic.backups."${name}" = {
passwordFile = toString (../secrets/restic_password);
s3CredentialsFile = toString ../secrets/s3_credentials;
repository = "s3:https://s3.eu-central-1.wasabisys.com/sbruder-restic";
paths = lib.mkDefault (
[ ]
++ maybePath /data
++ maybePath /home
++ maybePath /srv
++ maybePath /var
);
initialize = true;
extraBackupArgs = [
"--exclude-caches"
"--exclude-file=${excludesFile}"
"--verbose"
];
timerConfig = cfg.timerConfig;
};
systemd.services."restic-backups-${name}".serviceConfig = {
"Nice" = 10;
"IOSchedulingClass" = "best-effort";
"IOSchedulingPriority" = 7;
};
};
}