move ensureZfsMounts

This commit is contained in:
2025-08-11 16:18:10 -07:00
parent 80df89e9a1
commit 30421d96f0
5 changed files with 68 additions and 50 deletions

33
overlays.nix Normal file
View File

@@ -0,0 +1,33 @@
final: prev: {
ensureZfsMounts = prev.writeShellApplication {
name = "zfsEnsureMounted";
runtimeInputs = with prev; [
zfs
gnugrep
gawk
coreutils
];
text = ''
#!/bin/sh -x
if [[ "$#" -eq "0" ]]; then
echo "no arguments passed"
exit 1
fi
TARGETS=$(echo "$@" | sort | uniq)
MOUNTED=$(zfs list -o mountpoint,mounted -H | awk '$2 == "yes" {print $1}' | sort | uniq)
NUM_MATCHED=$(echo "$MOUNTED" | grep -Ec "$(echo "$@" | tr ' ' '\|')") # does not properly handle paths with strings
if [[ "$NUM_MATCHED" -eq "$#" ]]; then
exit 0
fi
FOUND=$(printf "%s\n%s" "$TARGETS" "$MOUNTED" | sort | uniq -c | awk '$1 == "2" {print $2}' | sort)
MISSING=$(printf "%s\n%s" "$FOUND" "$TARGETS" | sort | uniq -u | sort)
echo "FAILURE, missing: $MISSING" 1>&2
exit 1
'';
};
}