Skip to content

Commit

Permalink
Implement preMountHook & postMountHook
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
amarshall authored and mergify[bot] committed Nov 12, 2023
1 parent 01ec602 commit 2d7d778
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions example/complex.nix
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@
mountOptions = [
"defaults"
];
postMountHook = ''
touch /mnt/ext4_on_lvm/file-from-postMountHook
'';
};
};
raid1 = {
Expand Down
11 changes: 9 additions & 2 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
};

Expand Down
3 changes: 3 additions & 0 deletions tests/complex.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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" ];
Expand Down

0 comments on commit 2d7d778

Please sign in to comment.