nixos-config/common/hardware/btrfs.nix
2024-05-01 12:10:16 +02:00

37 lines
722 B
Nix

{
lib,
pkgs,
...
}: {
boot.initrd.availableKernelModules = [
# Btrfs CRC hardware acceleration
"crc32c-intel"
];
services.btrfs.autoScrub = {
enable = true;
interval = "monthly";
fileSystems = lib.mkDefault ["/"];
};
systemd.timers."btrfs-snapshot" = {
wantedBy = ["timers.target"];
timerConfig = {
OnCalendar = "weekly";
Persistent = true;
Unit = "btrfs-snapshot.service";
};
};
systemd.services."btrfs-snapshot" = {
script = ''
set -eu
${pkgs.btrfs-progs}/bin/btrfs subvolume snapshot /home /snapshots/home/$(date +"%Y-M%m-%d_%H-%M-%S") -r
'';
serviceConfig = {
Type = "oneshot";
User = "root";
};
};
}