use findmnt and mount with X-mount.mkdir

This feels slightly cleaner and makes the code shorter.
This commit is contained in:
Jörg Thalheim 2022-08-17 15:54:28 +02:00
parent f8522774e7
commit e123b05ff4
2 changed files with 7 additions and 5 deletions

View File

@ -88,9 +88,8 @@ let {
mount.filesystem = q: x: { mount.filesystem = q: x: {
fs.${x.mountpoint} = '' fs.${x.mountpoint} = ''
if ! [ "$(mount | sed -n 's:\([^ ]\+\) on /mnt${x.mountpoint} .*:\1:p')" = ${q.device} ]; then if ! findmnt "${q.device}" "/mnt${x.mountpoint}" > /dev/null 2>&1; then
mkdir -p /mnt${x.mountpoint} mount "${q.device}" "/mnt${x.mountpoint}" -o X-mount.mkdir
mount ${q.device} /mnt${x.mountpoint}
fi fi
''; '';
}; };

View File

@ -85,6 +85,8 @@ let
}; };
}; };
}; };
tsp-create = pkgs.writeScript "create" ((pkgs.callPackage ../. {}).create disko-config);
tsp-mount = pkgs.writeScript "mount" ((pkgs.callPackage ../. {}).mount disko-config);
in makeTest' { in makeTest' {
name = "disko"; name = "disko";
@ -105,8 +107,9 @@ in makeTest' {
testScript = '' testScript = ''
machine.succeed("echo 'secret' > /tmp/secret.key"); machine.succeed("echo 'secret' > /tmp/secret.key");
machine.succeed("${pkgs.writeScript "create" ((pkgs.callPackage ../. {}).create disko-config)}"); machine.succeed("${tsp-create}");
machine.succeed("${pkgs.writeScript "mount" ((pkgs.callPackage ../. {}).mount disko-config)}"); machine.succeed("${tsp-mount}");
machine.succeed("${tsp-mount}"); # verify that the command is idempotent
machine.succeed("test -b /dev/mapper/pool-raw"); machine.succeed("test -b /dev/mapper/pool-raw");
''; '';
} }