btrfssnapshot

This commit is contained in:
Motiejus Jakštys 2024-07-29 05:36:17 +03:00
parent 5cf65d35db
commit 2bbb8b5010
2 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,53 @@
{
config,
lib,
pkgs,
...
}: let
cfg = config.mj.base.btrfssnapshot;
in {
options.mj.base.btrfssnapshot = {
enable = lib.mkEnableOption "Enable btrfs snapshots";
subvolumes = lib.mkOption {
default = {};
type = with lib.types;
attrsOf (submodule {
options = {
label = lib.mkOption {type = str;};
keep = lib.mkOption {type = int;};
refreshInterval = lib.mkOption {type = str;};
};
});
};
};
config = lib.mkIf cfg.enable {
systemd = {
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}";
}
);
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;
}
);
};
};
}

View File

@ -9,6 +9,7 @@
in { in {
imports = [ imports = [
./boot ./boot
./btrfssnapshot
./fileSystems ./fileSystems
./snapshot ./snapshot
./sshd ./sshd