From 7f8278a2640dd74794550ba4c99e851f4b74c5a2 Mon Sep 17 00:00:00 2001 From: Andrew Marshall Date: Tue, 24 Sep 2024 22:02:03 -0400 Subject: [PATCH] nixos/zfs: do not auto-import pools marked noauto This requires all datasets for the pool specified in `fileSystems` to be marked noauto. Note that this implicitly skips some tasks for the pool, such as `expandOnBoot`, as the pool will not be imported at that time. --- nixos/doc/manual/release-notes/rl-2505.section.md | 2 ++ nixos/modules/tasks/filesystems/zfs.nix | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/nixos/doc/manual/release-notes/rl-2505.section.md b/nixos/doc/manual/release-notes/rl-2505.section.md index f3a58367e055..79ab29de8162 100644 --- a/nixos/doc/manual/release-notes/rl-2505.section.md +++ b/nixos/doc/manual/release-notes/rl-2505.section.md @@ -91,6 +91,8 @@ 2.0](https://github.com/containerd/containerd/blob/main/docs/containerd-2.0.md) documentation for more details. +- The ZFS import service now respects `fileSystems.*.options = [ "noauto" ];` and does not add that pool's import service to `zfs-import.target`, meaning it will not be automatically imported at boot. + - `nodePackages.stackdriver-statsd-backend` has been removed, as the StackDriver service has been discontinued by Google, and therefore the package no longer works. - the notmuch vim plugin now lives in a separate output of the `notmuch` diff --git a/nixos/modules/tasks/filesystems/zfs.nix b/nixos/modules/tasks/filesystems/zfs.nix index c07a09d701f6..27f2028a175d 100644 --- a/nixos/modules/tasks/filesystems/zfs.nix +++ b/nixos/modules/tasks/filesystems/zfs.nix @@ -128,7 +128,9 @@ let "systemd-modules-load.service" "systemd-ask-password-console.service" ] ++ lib.optional (config.boot.initrd.clevis.useTang) "network-online.target"; - requiredBy = getPoolMounts prefix pool ++ [ "zfs-import.target" ]; + requiredBy = let + noauto = lib.all (fs: lib.elem "noauto" fs.options) (getPoolFilesystems pool); + in getPoolMounts prefix pool ++ lib.optional (!noauto) "zfs-import.target"; before = getPoolMounts prefix pool ++ [ "shutdown.target" "zfs-import.target" ]; conflicts = [ "shutdown.target" ]; unitConfig = {