Implement preMountHook & postMountHook

These options previously existed but had no effect. Now they are
implemented. They only affect mount during disko’s filesystem creation,
not during any later mounts.

Adding test case to existing “complex” example and test mostly because
couldn’t think of any better place to put it.
This commit is contained in:
Andrew Marshall 2023-11-10 22:29:44 -05:00 committed by mergify[bot]
parent 01ec6024d6
commit 2d7d77878c
3 changed files with 15 additions and 2 deletions

View File

@ -110,6 +110,9 @@
mountOptions = [
"defaults"
];
postMountHook = ''
touch /mnt/ext4_on_lvm/file-from-postMountHook
'';
};
};
raid1 = {

View File

@ -238,12 +238,19 @@ let
description = "Creation script";
};
mkMountOption = { default, ... }@attrs:
mkMountOption = { config, options, default }@attrs:
lib.mkOption {
internal = true;
readOnly = true;
type = diskoLib.jsonType;
default = attrs.default;
default = lib.mapAttrsRecursive (name: value: if builtins.isString value then ''
(
${diskoLib.indent (diskoLib.defineHookVariables { inherit options; })}
${config.preMountHook}
${diskoLib.indent value}
${config.postMountHook}
)
'' else value) attrs.default;
description = "Mount script";
};

View File

@ -20,6 +20,9 @@ diskoLib.testLib.makeDiskoTest {
machine.succeed("mountpoint /zfs_legacy_fs");
machine.succeed("mountpoint /ext4onzfs");
machine.succeed("mountpoint /ext4_on_lvm");
machine.succeed("test -e /ext4_on_lvm/file-from-postMountHook");
'';
extraInstallerConfig = {
boot.kernelModules = [ "dm-raid" "dm-mirror" ];