From df8a22760c8df918e6e67abcb6e56aeaa9ab6362 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Thu, 21 Aug 2025 05:02:05 -0400 Subject: [PATCH] add lib.serviceDependZpool --- lib.nix | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib.nix b/lib.nix index 5fa56af..bb21808 100644 --- a/lib.nix +++ b/lib.nix @@ -78,5 +78,24 @@ inputs.nixpkgs.lib.extend ( vpnNamespace = "wg"; }; }; + + serviceDependZpool = + serviceName: zpool: + { config, ... }: + { + systemd.services.${serviceName} = { + wants = [ "zfs-import-${zpool}.service" ]; + after = [ "zfs-import-${zpool}.service" ]; + requires = [ "zfs-import-${zpool}.service" ]; + }; + + # assert that the pool is even enabled + config.assertions = [ + { + assertion = builtins.elem zpool config.boot.zfs.extraPools; + message = "${zpool} is not enabled in `boot.zfs.extraPools`"; + } + ]; + }; } )