From 70964072b6a872a4ba794e95401bb6c584ffec7d Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Sat, 26 Oct 2024 00:01:11 +0200 Subject: [PATCH] Fix race condition in partition script --- lib/modules/partition/disks.nix | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/modules/partition/disks.nix b/lib/modules/partition/disks.nix index e8764a2f..ba783123 100644 --- a/lib/modules/partition/disks.nix +++ b/lib/modules/partition/disks.nix @@ -91,9 +91,14 @@ let type); fdiskCommand = arguments: "sudo sfdisk ${arguments}"; - fdiskScript = script: append: "echo ${script} | ${fdiskCommand "${if append then "--append" else ""} ${diskVar}"}"; - wipeScript = script: fdiskScript script false; - appendScript = script: fdiskScript script true; + fdiskScript = script: args: append: + "echo ${script} | ${ + fdiskCommand "${builtins.concatStringsSep " " args} ${ + if append then "--append" else "" + } ${diskVar}" + }"; + wipeScript = script: fdiskScript script [] false; + appendScript = index: script: fdiskScript script ["-N" (builtins.toString index)] true; cleanup = lib.strings.concatLines (builtins.map (partition: "${fdiskCommand "--delete ${diskVar} ${toString partition.index}"} || true") @@ -130,7 +135,7 @@ let }; create = lib.strings.concatLines [ - (appendScript ''${toString index}: "$(${sizeOption})" type=${mkType type}'') + (appendScript index ''${toString index}: "$(${sizeOption})" type=${mkType type}'') probeScript "sudo ${formatScripts.${format}}" ];