servers/common/backups/restic.nix

78 lines
1.4 KiB
Nix
Raw Normal View History

{
config,
pkgs,
lib,
...
2026-02-24 00:00:35 -08:00
}:
let
inherit (lib)
mkIf
mkEnableOption
mkOption
types
;
cfg = config.foehammer.backups.restic;
2026-02-24 00:00:35 -08:00
in
{
options.foehammer.backups.restic = {
enable = mkEnableOption "Enable restic backups";
repositoryFile = mkOption {
type = types.nullOr types.path;
};
environmentFile = mkOption {
type = types.nullOr types.str;
};
passwordFile = mkOption {
type = types.str;
};
paths = mkOption {
type = lib.types.nullOr (lib.types.listOf lib.types.str);
2026-02-24 00:00:35 -08:00
default = [ ];
};
exclude = mkOption {
type = lib.types.nullOr (lib.types.listOf lib.types.str);
2026-02-24 00:00:35 -08:00
default = [ ];
};
};
config = mkIf cfg.enable {
2026-02-24 00:00:35 -08:00
users.groups.restic = { };
users.users.restic = {
isSystemUser = true;
group = "restic";
};
security.wrappers.restic = {
source = "${pkgs.restic.out}/bin/restic";
owner = "restic";
group = "restic";
permissions = "u=rwx,g=,o=";
capabilities = "cap_dac_read_search=+ep";
};
services.restic.backups = {
remote = {
paths = cfg.paths;
exclude = cfg.exclude;
user = "restic";
initialize = true;
repositoryFile = cfg.repositoryFile;
environmentFile = cfg.environmentFile;
passwordFile = cfg.passwordFile;
pruneOpts = [
"--keep-daily 7"
"--keep-weekly 4"
];
};
};
};
}