restic: Parameterise extra paths and excludes

This commit is contained in:
Simon Bruder 2020-12-21 13:09:25 +01:00
parent 5937065d0e
commit b435e1a182
No known key found for this signature in database
GPG key ID: 6F03E0000CC5B62F
2 changed files with 21 additions and 10 deletions

View file

@ -12,7 +12,12 @@
gpu.amd.enable = true; gpu.amd.enable = true;
gui.enable = true; gui.enable = true;
libvirt.enable = true; libvirt.enable = true;
restic.enable = true; restic = {
enable = true;
extraPaths = [
"/data"
];
};
ssd.enable = true; ssd.enable = true;
wireguard.home = { wireguard.home = {
enable = true; enable = true;

View file

@ -27,9 +27,8 @@ let
# Docker (state should be kept somewhere else) # Docker (state should be kept somewhere else)
"/var/lib/docker/" "/var/lib/docker/"
]; ] ++ cfg.extraExcludes;
excludesFile = pkgs.writeText "exludes.txt" (builtins.concatStringsSep "\n" excludes); excludesFile = pkgs.writeText "exludes.txt" (builtins.concatStringsSep "\n" excludes);
maybePath = path: (lib.optional (builtins.pathExists path) (toString path));
# script to use restic as user without dealing with authentication # script to use restic as user without dealing with authentication
authScript = pkgs.writeShellScriptBin "restic-auth" '' authScript = pkgs.writeShellScriptBin "restic-auth" ''
@ -57,6 +56,15 @@ in
RandomizedDelaySec = "2h"; RandomizedDelaySec = "2h";
}; };
}; };
extraPaths = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
example = [ "/data" ];
};
extraExcludes = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
};
}; };
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
@ -64,13 +72,11 @@ in
inherit repository; inherit repository;
passwordFile = toString <secrets/restic-password>; passwordFile = toString <secrets/restic-password>;
s3CredentialsFile = toString <secrets/restic-s3>; s3CredentialsFile = toString <secrets/restic-s3>;
paths = lib.mkDefault ( paths = [
[ ] "/home"
++ maybePath /data "/srv"
++ maybePath /home "/var"
++ maybePath /srv ] ++ cfg.extraPaths;
++ maybePath /var
);
initialize = true; initialize = true;
extraBackupArgs = [ extraBackupArgs = [
"--exclude-caches" "--exclude-caches"