From 2d7d77878c5d70f66f3d676ff66708d8d4f9d7df Mon Sep 17 00:00:00 2001 From: Andrew Marshall Date: Fri, 10 Nov 2023 22:29:44 -0500 Subject: [PATCH] Implement preMountHook & postMountHook MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- example/complex.nix | 3 +++ lib/default.nix | 11 +++++++++-- tests/complex.nix | 3 +++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/example/complex.nix b/example/complex.nix index 08a88ed..36a962c 100644 --- a/example/complex.nix +++ b/example/complex.nix @@ -110,6 +110,9 @@ mountOptions = [ "defaults" ]; + postMountHook = '' + touch /mnt/ext4_on_lvm/file-from-postMountHook + ''; }; }; raid1 = { diff --git a/lib/default.nix b/lib/default.nix index b2e2014..9cd2239 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -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"; }; diff --git a/tests/complex.nix b/tests/complex.nix index c5aff2d..c29e997 100644 --- a/tests/complex.nix +++ b/tests/complex.nix @@ -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" ];