git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #70601 from Mic92/zfs-trim

nixos/zfs: only enable trim if zfs is enabled

commitd633ec9787a7060d0f9bc42941759a3573a1d14b authorJörg Thalheim <Mic92@users.noreply.github.com> dateMon 14 Oct 2019, 11:04 (7 years ago) parent283ef6b12880e5
2 files changed+19−10
nixos/doc/manual/release-notes/rl-2003.xml+13 nixos/modules/tasks/filesystems/zfs.nix+6−10
nixos/doc/manual/release-notes/rl-2003.xml+13
@@ -36,6 +36,19 @@
3636 quirk in the boot menu.
3737 </para>
3838 </listitem>
39+ <listitem>
40+ <para>
41+ By default zfs pools will now be trimmed on a weekly basis.
42+ Trimming is only done on supported devices (i.e. NVME or SSDs)
43+ and should improve throughput and lifetime of these devices.
44+ It is controlled by the <varname>services.zfs.trim.enable</varname> varname.
45+ The zfs scrub service (<varname>services.zfs.autoScrub.enable</varname>)
46+ and the zfs autosnapshot service (<varname>services.zfs.autoSnapshot.enable</varname>)
47+ are now only enabled if zfs is set in <varname>config.boot.initrd.supportedFilesystems</varname> or
48+ <varname>config.boot.supportedFilesystems</varname>. These lists will automatically contain
49+ zfs as soon as any zfs mountpoint is configured in <varname>fileSystems</varname>.
50+ </para>
51+ </listitem>
3952 </itemizedlist>
4053 </section>
4154
nixos/modules/tasks/filesystems/zfs.nix+6−10
@@ -16,9 +16,7 @@ let
1616 inInitrd = any (fs: fs == "zfs") config.boot.initrd.supportedFilesystems;
1717 inSystem = any (fs: fs == "zfs") config.boot.supportedFilesystems;
1818
19− enableAutoSnapshots = cfgSnapshots.enable;
20− enableAutoScrub = cfgScrub.enable;
21− enableZfs = inInitrd || inSystem || enableAutoSnapshots || enableAutoScrub;
19+ enableZfs = inInitrd || inSystem;
2220
2321 kernel = config.boot.kernelPackages;
2422
@@ -395,7 +393,7 @@ in
395393
396394 system.fsPackages = [ packages.zfsUser ]; # XXX: needed? zfs doesn't have (need) a fsck
397395 environment.systemPackages = [ packages.zfsUser ]
398− ++ optional enableAutoSnapshots autosnapPkg; # so the user can run the command to see flags
396+ ++ optional cfgSnapshots.enable autosnapPkg; # so the user can run the command to see flags
399397
400398 services.udev.packages = [ packages.zfsUser ]; # to hook zvol naming, etc.
401399 systemd.packages = [ packages.zfsUser ];
@@ -487,7 +485,7 @@ in
487485 systemd.targets.zfs.wantedBy = [ "multi-user.target" ];
488486 })
489487
490− (mkIf enableAutoSnapshots {
488+ (mkIf (enableZfs && cfgSnapshots.enable) {
491489 systemd.services = let
492490 descr = name: if name == "frequent" then "15 mins"
493491 else if name == "hourly" then "hour"
@@ -525,7 +523,7 @@ in
525523 }) snapshotNames);
526524 })
527525
528− (mkIf enableAutoScrub {
526+ (mkIf (enableZfs && cfgScrub.enable) {
529527 systemd.services.zfs-scrub = {
530528 description = "ZFS pools scrubbing";
531529 after = [ "zfs-import.target" ];
@@ -552,15 +550,13 @@ in
552550 };
553551 })
554552
555− (mkIf cfgTrim.enable {
553+ (mkIf (enableZfs && cfgTrim.enable) {
556554 systemd.services.zpool-trim = {
557555 description = "ZFS pools trim";
558556 after = [ "zfs-import.target" ];
559557 path = [ packages.zfsUser ];
560558 startAt = cfgTrim.interval;
561− script = ''
562− zpool list -H -o name | xargs -n1 zpool trim
563− '';
559+ serviceConfig.ExecStart = "${pkgs.runtimeShell} -c 'zpool list -H -o name | xargs --no-run-if-empty -n1 zpool trim'";
564560 };
565561 })
566562 ];