summaryrefslogtreecommitdiffstats
path: root/configs
diff options
context:
space:
mode:
Diffstat (limited to 'configs')
-rw-r--r--configs/btrfs-scrub.nix43
1 files changed, 43 insertions, 0 deletions
diff --git a/configs/btrfs-scrub.nix b/configs/btrfs-scrub.nix
new file mode 100644
index 00000000..3fa168b3
--- /dev/null
+++ b/configs/btrfs-scrub.nix
@@ -0,0 +1,43 @@
+{ config, lib, utils, ... }: let
+
+ names =
+ map (fs: "btrfs-scrub-${utils.escapeSystemdPath fs}")
+ config.services.btrfs.autoScrub.fileSystems;
+
+in {
+
+ assertions = [
+ {
+ assertion = names != [];
+ message = ''
+ configs/btrfs-scrub.nix: services.btrfs.autoScrub.fileSystems is empty.
+ Most likely the system doesn't use btrfs but imports this file.
+ '';
+ }
+ {
+ assertion = lib.all (name: builtins.hasAttr name config.systemd.timers) names;
+ message = ''
+ configs/btrfs-scrub.nix: services.btrfs.autoScrub has no timers named
+ after its file systems. Most likely it uses template units now.
+ '';
+ }
+ ];
+
+ services.btrfs.autoScrub.enable = true;
+
+ # Not on battery. A scrub skipped for that waits for the next week's.
+ systemd.services = lib.genAttrs names (_: {
+ unitConfig.ConditionACPower = true;
+ });
+
+ systemd.timers = lib.genAttrs names (_: {
+ timerConfig = {
+ OnCalendar = lib.mkForce "Mon *-*-* 07:00:00";
+ # NixOS allows a day, which would move the scrub out of its window.
+ AccuracySec = lib.mkForce "1min";
+ RandomizedDelaySec = "4h";
+ };
+ });
+
+ krebs.on-failure.plans = lib.genAttrs names (_: {});
+}