From c70f0473153c63ad1cf6fbea19f290db6b15291f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Mon, 28 Nov 2022 13:35:48 +0100 Subject: [PATCH] nixos/zfs: assert no force import with hibernation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit According to a ZFS issue about hibernation causing data corruption: https://github.com/openzfs/zfs/issues/12842 The way this happens is if the system force imports a pool that was suspended during hibernation. I've had this happen twice on NixOS and I'd like to avoid having this happen again, to me or others. To do this I've added an assertion that makes sure you can't have `forceImportRoot` or `forceImportAll` enabled with `allowHibernation`. Signed-off-by: Jakub SokoĊ‚owski --- nixos/modules/tasks/filesystems/zfs.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nixos/modules/tasks/filesystems/zfs.nix b/nixos/modules/tasks/filesystems/zfs.nix index 4b4f4cc801ab..0f14f2b501c2 100644 --- a/nixos/modules/tasks/filesystems/zfs.nix +++ b/nixos/modules/tasks/filesystems/zfs.nix @@ -503,6 +503,10 @@ in assertion = !cfgZfs.forceImportAll || cfgZfs.forceImportRoot; message = "If you enable boot.zfs.forceImportAll, you must also enable boot.zfs.forceImportRoot"; } + { + assertion = cfgZfs.allowHibernation -> !cfgZfs.forceImportRoot && !cfgZfs.forceImportAll; + message = "boot.zfs.allowHibernation while force importing is enabled will cause data corruption"; + } ]; boot = {