@ -1,8 +1,6 @@
{ config , lib , pkgs , utils , . . . }:
#
# todo:
# - crontab for scrubs, etc
# - zfs tunables
# TODO: zfs tunables
with utils ;
with lib ;
@ -13,6 +11,7 @@ let
cfgSnapshots = config . services . zfs . autoSnapshot ;
cfgSnapFlags = cfgSnapshots . flags ;
cfgScrub = config . services . zfs . autoScrub ;
cfgTrim = config . services . zfs . trim ;
inInitrd = any ( fs : fs == " z f s " ) config . boot . initrd . supportedFilesystems ;
inSystem = any ( fs : fs == " z f s " ) config . boot . supportedFilesystems ;
@ -268,14 +267,26 @@ in
} ;
} ;
services . zfs . autoScrub = {
enable = mkOption {
default = false ;
type = types . bool ;
services . zfs . trim = {
enable = mkEnableOption " E n a b l e s p e r i o d i c T R I M o n a l l Z F S p o o l s . " ;
interval = mkOption {
default = " w e e k l y " ;
type = types . str ;
example = " d a i l y " ;
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 " E n a b l e s p e r i o d i c s c r u b b i n g o f Z F S p o o l s . " ;
interval = mkOption {
default = " S u n , 0 2 : 0 0 " ;
@ -535,5 +546,17 @@ in
} ;
} ;
} )
( mkIf cfgTrim . enable {
systemd . services . zpool-trim = {
description = " Z F S p o o l s t r i m " ;
after = [ " z f s - i m p o r t . t a r g e t " ] ;
path = [ packages . zfsUser ] ;
startAt = cfgTrim . interval ;
script = ''
zpool list - H - o name | xargs - n1 zpool trim
'' ;
} ;
} )
] ;
}