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
;
partVarName = "myPartition";
partVar = ''''${${partVarName}}'';
sizeOption = ''
${sizeScript} | sed -e "s/.*[^[:space:]]/size=\0/"
'';
formatScripts = {
${fs.ext4} = "mkfs.ext4 -F ${diskVar}";
${fs.swap} = "mkswap ${diskVar}";
${fs.ntfs} = "mkfs.ntfs -F ${diskVar}";
${fs.fat32} = "mkfs.fat -F 32 ${diskVar}";
${fs.ext4} = "mkfs.ext4 -F ${partVar}";
${fs.swap} = "mkswap ${partVar}";
${fs.ntfs} = "mkfs.ntfs -F ${partVar}";
${fs.fat32} = "mkfs.fat -F 32 ${partVar}";
};
labelScripts = {
${fs.ext4} = label: "e2label ${diskVar} ${label}";
${fs.swap} = label: "swaplabel ${diskVar} ${label}";
${fs.ntfs} = label: "ntfslabel ${diskVar} ${label}";
${fs.fat32} = label: "fatlabel ${diskVar} ${label}";
${fs.ext4} = label: "e2label ${partVar} ${label}";
${fs.swap} = label: "swaplabel ${partVar} ${label}";
${fs.ntfs} = label: "ntfslabel ${partVar} ${label}";
${fs.fat32} = label: "fatlabel ${partVar} ${label}";
};
create = lib.strings.concatLines [
(appendScript "${toString index}: \"$(${sizeOption})\" type=${lib.strings.escapeShellArg type}")
formatScripts.${format}
];
fallback = ''
@ -125,6 +127,9 @@
'';
in [
(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)
])
partitions)