{ 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 (_: {}); }