config/modules/base/btrfssnapshot/default.nix

49 lines
1.3 KiB
Nix
Raw Normal View History

2024-07-29 05:36:17 +03:00
{
config,
lib,
pkgs,
...
2024-07-29 15:39:54 +03:00
}:
let
2024-07-29 05:36:17 +03:00
cfg = config.mj.base.btrfssnapshot;
2024-07-29 15:39:54 +03:00
in
{
2024-07-29 05:36:17 +03:00
options.mj.base.btrfssnapshot = {
enable = lib.mkEnableOption "Enable btrfs snapshots";
subvolumes = lib.mkOption {
2024-07-29 15:39:54 +03:00
default = { };
type =
with lib.types;
2024-07-29 05:36:17 +03:00
attrsOf (submodule {
options = {
2024-07-29 15:39:54 +03:00
label = lib.mkOption { type = str; };
keep = lib.mkOption { type = int; };
refreshInterval = lib.mkOption { type = str; };
2024-07-29 05:36:17 +03:00
};
});
};
};
config = lib.mkIf cfg.enable {
systemd = {
2024-07-29 15:39:54 +03:00
services = lib.mapAttrs' (
subvolume: params:
lib.nameValuePair "btrfs-snapshot-${lib.strings.sanitizeDerivationName subvolume}" {
description = "${params.label} btrfs snapshot for ${subvolume} (keep ${params.keep}";
serviceConfig.ExecStart = "${pkgs.btrfs-auto-snapshot} --verbose --label=${params.label} --keep=${params.keep} ${subvolume}";
}
);
2024-07-29 05:36:17 +03:00
2024-07-29 15:39:54 +03:00
timers = lib.mapAttrs' (
subvolume: params:
lib.nameValuePair "btrfs-snapshot-${lib.strings.sanitizeDerivationName subvolume}" {
description = "${params.label} btrfs snapshot for ${subvolume}";
wantedBy = [ "timers.target" ];
timerConfig.OnCalendar = params.refreshInterval;
}
);
2024-07-29 05:36:17 +03:00
};
};
}