From 9a8e0d1c2ef11a2ae0b7b5669ff28059db1dde4f Mon Sep 17 00:00:00 2001 From: Svein Ove Aas Date: Tue, 19 Jul 2016 08:57:13 +0100 Subject: [PATCH] zfs: Force sync on shutdown (#16903) --- nixos/modules/tasks/filesystems/zfs.nix | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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" ]; };