Ensure partition presence using partprobe

This commit is contained in:
Manuel Thalmann 2024-09-12 18:39:18 +02:00
parent ef271779d0
commit 0a5dc5deaa

View file

@ -8,6 +8,7 @@
fs = import ./fs.nix; fs = import ./fs.nix;
diskListVarName = "myDisks"; diskListVarName = "myDisks";
probeScript = "partprobe 2> /dev/null || true";
isSwap = partition: builtins.elem partition.type [fs.swap 19]; isSwap = partition: builtins.elem partition.type [fs.swap 19];
mkDiskType = osDisk: types.submodule ( mkDiskType = osDisk: types.submodule (
@ -136,14 +137,7 @@
create = lib.strings.concatLines [ create = lib.strings.concatLines [
(appendScript "${toString index}: \"$(${sizeOption})\" type=${mkType type}") (appendScript "${toString index}: \"$(${sizeOption})\" type=${mkType type}")
# Wait for partition to be detected probeScript
''echo "Waiting for ${partVar} to appear..."''
''
while true;
do
[ -b ${partVar} ] && break;
done;
''
"sudo ${formatScripts.${format}}" "sudo ${formatScripts.${format}}"
]; ];
@ -329,13 +323,7 @@
mountScript = lib.strings.concatLines ( mountScript = lib.strings.concatLines (
builtins.concatMap builtins.concatMap
(_: [ (_: [
''echo "Waiting for "${lib.strings.escapeShellArg (partPath _)}" to appear..."'' probeScript
''
while true;
do
[ -b ${lib.strings.escapeShellArg (partPath _)} ] && break
done
''
(builtins.concatStringsSep " " [ (builtins.concatStringsSep " " [
"sudo" "sudo"
"mount" "mount"
@ -351,7 +339,10 @@
swapScript = lib.strings.concatLines ( swapScript = lib.strings.concatLines (
builtins.map builtins.map
(_: "sudo swapon ${partPath _}") (_: ''
${probeScript}
sudo swapon ${partPath _}
'')
(builtins.filter (_: _.useSwap) partitions)); (builtins.filter (_: _.useSwap) partitions));
in lib.strings.concatLines ( in lib.strings.concatLines (
(builtins.map (_: _.deviceScript) disks) ++ lib.optionals ((builtins.length disks) > 0) [ (builtins.map (_: _.deviceScript) disks) ++ lib.optionals ((builtins.length disks) > 0) [