It’s generally a good idea to avoid activation scripts when possible. Activation is run at very sensitive times, and when things go wrong in activation they cause huge problems. I would probably have created systemd services to handle this. Something like:
{ pkgs, lib, config, utils, ... }: {
systemd.services."zfs-create-${utils.escapeSystemdPath dataset}" = {
unitConfig.DefaultDependencies = false;
requiredBy = [ "local-fs.target" ];
before = [ "local-fs.target" ];
after = [ "zfs-import-${pool}.service" "zfs-mount.service" ];
unitConfig.ConditionPathIsMountPoint = "!${mountpoint}";
script = ''
${config.boot.zfs.package}/bin/zfs create -o mountpoint=${mountpoint} -o recordsize=8k -p ${dataset}
chmod 700 ${mountpoint}
'';
};
}
I did some systemd trickery with ConditionPathIsMountPoint
. By ordering after zfs-mount.service
, I’ve ensured that any existing datasets are already mounted, then ConditionPathIsMountPoint
(with the negation !
) causes this service to be skipped if this dataset already exists and is therefore mounted.