add lib.serviceDependZpool

This commit is contained in:
Simon Gardling 2025-08-21 05:02:05 -04:00
parent a827438a4c
commit df8a22760c
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D

19
lib.nix
View File

@ -78,5 +78,24 @@ inputs.nixpkgs.lib.extend (
vpnNamespace = "wg"; 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`";
}
];
};
} }
) )