summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJörg Thalheim <joerg@thalheim.io>2022-08-17 15:54:28 +0200
committerJörg Thalheim <joerg@thalheim.io>2022-08-17 15:55:07 +0200
commite123b05ff4226fba308d0cffc259817fa3425d1d (patch)
treeff101efd7096c6add300ad99290e493820a7e1df
parentf8522774e77789ba4b5fd0581daacf4747a5360f (diff)
use findmnt and mount with X-mount.mkdir
This feels slightly cleaner and makes the code shorter.
-rw-r--r--lib/default.nix5
-rw-r--r--tests/test.nix7
2 files changed, 7 insertions, 5 deletions
diff --git a/lib/default.nix b/lib/default.nix
index beba1b0..edc0062 100644
--- a/lib/default.nix
+++ b/lib/default.nix
@@ -88,9 +88,8 @@ let {
mount.filesystem = q: x: {
fs.${x.mountpoint} = ''
- if ! [ "$(mount | sed -n 's:\([^ ]\+\) on /mnt${x.mountpoint} .*:\1:p')" = ${q.device} ]; then
- mkdir -p /mnt${x.mountpoint}
- mount ${q.device} /mnt${x.mountpoint}
+ if ! findmnt "${q.device}" "/mnt${x.mountpoint}" > /dev/null 2>&1; then
+ mount "${q.device}" "/mnt${x.mountpoint}" -o X-mount.mkdir
fi
'';
};
diff --git a/tests/test.nix b/tests/test.nix
index fa89208..82976ba 100644
--- a/tests/test.nix
+++ b/tests/test.nix
@@ -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' {
name = "disko";
@@ -105,8 +107,9 @@ in makeTest' {
testScript = ''
machine.succeed("echo 'secret' > /tmp/secret.key");
- machine.succeed("${pkgs.writeScript "create" ((pkgs.callPackage ../. {}).create disko-config)}");
- machine.succeed("${pkgs.writeScript "mount" ((pkgs.callPackage ../. {}).mount disko-config)}");
+ machine.succeed("${tsp-create}");
+ machine.succeed("${tsp-mount}");
+ machine.succeed("${tsp-mount}"); # verify that the command is idempotent
machine.succeed("test -b /dev/mapper/pool-raw");
'';
}