Execute formatting scripts on partition

This commit is contained in:
Manuel Thalmann 2024-06-22 21:42:43 +02:00
parent 1c845c3e1d
commit 04d3548f27

View file

@ -94,27 +94,29 @@
type type
; ;
partVarName = "myPartition";
partVar = ''''${${partVarName}}'';
sizeOption = '' sizeOption = ''
${sizeScript} | sed -e "s/.*[^[:space:]]/size=\0/" ${sizeScript} | sed -e "s/.*[^[:space:]]/size=\0/"
''; '';
formatScripts = { formatScripts = {
${fs.ext4} = "mkfs.ext4 -F ${diskVar}"; ${fs.ext4} = "mkfs.ext4 -F ${partVar}";
${fs.swap} = "mkswap ${diskVar}"; ${fs.swap} = "mkswap ${partVar}";
${fs.ntfs} = "mkfs.ntfs -F ${diskVar}"; ${fs.ntfs} = "mkfs.ntfs -F ${partVar}";
${fs.fat32} = "mkfs.fat -F 32 ${diskVar}"; ${fs.fat32} = "mkfs.fat -F 32 ${partVar}";
}; };
labelScripts = { labelScripts = {
${fs.ext4} = label: "e2label ${diskVar} ${label}"; ${fs.ext4} = label: "e2label ${partVar} ${label}";
${fs.swap} = label: "swaplabel ${diskVar} ${label}"; ${fs.swap} = label: "swaplabel ${partVar} ${label}";
${fs.ntfs} = label: "ntfslabel ${diskVar} ${label}"; ${fs.ntfs} = label: "ntfslabel ${partVar} ${label}";
${fs.fat32} = label: "fatlabel ${diskVar} ${label}"; ${fs.fat32} = label: "fatlabel ${partVar} ${label}";
}; };
create = lib.strings.concatLines [ create = lib.strings.concatLines [
(appendScript "${toString index}: \"$(${sizeOption})\" type=${lib.strings.escapeShellArg type}") (appendScript "${toString index}: \"$(${sizeOption})\" type=${lib.strings.escapeShellArg type}")
formatScripts.${format}
]; ];
fallback = '' fallback = ''
@ -125,6 +127,9 @@
''; '';
in [ in [
(if keepExisting then fallback else create) (if keepExisting then fallback else create)
''local diskPath="$(find -L /dev/disk/by-diskseq -samefile ${diskVar})"''
''local ${partVarName}="$diskPath-part${toString index}"''
formatScripts.${format}
(labelScripts.${format} label) (labelScripts.${format} label)
]) ])
partitions) partitions)