summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorSvein Ove Aas <svein.ove@aas.no>2016-07-19 08:57:13 +0100
committerFranz Pletz <fpletz@fnordicwalking.de>2016-07-19 09:57:13 +0200
commit9a8e0d1c2ef11a2ae0b7b5669ff28059db1dde4f (patch)
treee1acde1fb9110dae5abb69d2181b00a7973ffd36 /nixos
parente54ec2f907e8980027ba040f11375adac478cc84 (diff)
downloadnixlib-9a8e0d1c2ef11a2ae0b7b5669ff28059db1dde4f.tar
nixlib-9a8e0d1c2ef11a2ae0b7b5669ff28059db1dde4f.tar.gz
nixlib-9a8e0d1c2ef11a2ae0b7b5669ff28059db1dde4f.tar.bz2
nixlib-9a8e0d1c2ef11a2ae0b7b5669ff28059db1dde4f.tar.lz
nixlib-9a8e0d1c2ef11a2ae0b7b5669ff28059db1dde4f.tar.xz
nixlib-9a8e0d1c2ef11a2ae0b7b5669ff28059db1dde4f.tar.zst
nixlib-9a8e0d1c2ef11a2ae0b7b5669ff28059db1dde4f.zip
zfs: Force sync on shutdown (#16903)
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/tasks/filesystems/zfs.nix18
1 files changed, 17 insertions, 1 deletions
diff --git a/nixos/modules/tasks/filesystems/zfs.nix b/nixos/modules/tasks/filesystems/zfs.nix
index 19292bd1ef71..80aec1bba0f3 100644
--- a/nixos/modules/tasks/filesystems/zfs.nix
+++ b/nixos/modules/tasks/filesystems/zfs.nix
@@ -270,7 +270,23 @@ in
               ("$zpool_cmd" list "${pool}" >/dev/null) || "$zpool_cmd" import -d ${cfgZfs.devNodes} -N ${optionalString cfgZfs.forceImportAll "-f"} "${pool}"
             '';
           };
-      in listToAttrs (map createImportService dataPools) // {
+
+        # This forces a sync of any ZFS pools prior to poweroff, even if they're set
+        # to sync=disabled.
+        createSyncService = pool:
+          nameValuePair "zfs-sync-${pool}" {
+            description = "Sync ZFS pool \"${pool}\"";
+            wantedBy = [ "shutdown.target" ];
+            serviceConfig = {
+              Type = "oneshot";
+              RemainAfterExit = true;
+            };
+            script = ''
+              ${zfsUserPkg}/sbin/zfs set nixos:shutdown-time="$(date)" "${pool}"
+            '';
+          };
+
+      in listToAttrs (map createImportService dataPools ++ map createSyncService allPools) // {
         "zfs-mount" = { after = [ "systemd-modules-load.service" ]; };
         "zfs-share" = { after = [ "systemd-modules-load.service" ]; };
         "zed" = { after = [ "systemd-modules-load.service" ]; };