Merge pull request #65331 from Mic92/zfs-trim
nixos/zfs: add trim service
This commit is contained in:
commit
741046a4d6
|
@ -1,8 +1,6 @@
|
||||||
{ config, lib, pkgs, utils, ... }:
|
{ config, lib, pkgs, utils, ... }:
|
||||||
#
|
#
|
||||||
# todo:
|
# TODO: zfs tunables
|
||||||
# - crontab for scrubs, etc
|
|
||||||
# - zfs tunables
|
|
||||||
|
|
||||||
with utils;
|
with utils;
|
||||||
with lib;
|
with lib;
|
||||||
|
@ -13,6 +11,7 @@ let
|
||||||
cfgSnapshots = config.services.zfs.autoSnapshot;
|
cfgSnapshots = config.services.zfs.autoSnapshot;
|
||||||
cfgSnapFlags = cfgSnapshots.flags;
|
cfgSnapFlags = cfgSnapshots.flags;
|
||||||
cfgScrub = config.services.zfs.autoScrub;
|
cfgScrub = config.services.zfs.autoScrub;
|
||||||
|
cfgTrim = config.services.zfs.trim;
|
||||||
|
|
||||||
inInitrd = any (fs: fs == "zfs") config.boot.initrd.supportedFilesystems;
|
inInitrd = any (fs: fs == "zfs") config.boot.initrd.supportedFilesystems;
|
||||||
inSystem = any (fs: fs == "zfs") config.boot.supportedFilesystems;
|
inSystem = any (fs: fs == "zfs") config.boot.supportedFilesystems;
|
||||||
|
@ -268,14 +267,26 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
services.zfs.autoScrub = {
|
services.zfs.trim = {
|
||||||
enable = mkOption {
|
enable = mkEnableOption "Enables periodic TRIM on all ZFS pools.";
|
||||||
default = false;
|
|
||||||
type = types.bool;
|
interval = mkOption {
|
||||||
|
default = "weekly";
|
||||||
|
type = types.str;
|
||||||
|
example = "daily";
|
||||||
description = ''
|
description = ''
|
||||||
Enables periodic scrubbing of ZFS pools.
|
How often we run trim. For most desktop and server systems
|
||||||
|
a sufficient trimming frequency is once a week.
|
||||||
|
|
||||||
|
The format is described in
|
||||||
|
<citerefentry><refentrytitle>systemd.time</refentrytitle>
|
||||||
|
<manvolnum>7</manvolnum></citerefentry>.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
services.zfs.autoScrub = {
|
||||||
|
enable = mkEnableOption "Enables periodic scrubbing of ZFS pools.";
|
||||||
|
|
||||||
interval = mkOption {
|
interval = mkOption {
|
||||||
default = "Sun, 02:00";
|
default = "Sun, 02:00";
|
||||||
|
@ -535,5 +546,17 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
|
(mkIf cfgTrim.enable {
|
||||||
|
systemd.services.zpool-trim = {
|
||||||
|
description = "ZFS pools trim";
|
||||||
|
after = [ "zfs-import.target" ];
|
||||||
|
path = [ packages.zfsUser ];
|
||||||
|
startAt = cfgTrim.interval;
|
||||||
|
script = ''
|
||||||
|
zpool list -H -o name | xargs -n1 zpool trim
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
})
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue