Allow formatting partitions in the script

This commit is contained in:
Manuel Thalmann 2024-06-22 20:00:03 +02:00
parent 046174da15
commit 3c73b0851c

View file

@ -5,6 +5,12 @@
diskVar = ''''${${diskVarName}}''; diskVar = ''''${${diskVarName}}'';
isSwap = partition: builtins.elem partition.type ["swap" 19]; isSwap = partition: builtins.elem partition.type ["swap" 19];
fs = {
ext4 = "ext4";
ntfs = "ntfs";
fat32 = "fat32";
};
diskSelector = '' diskSelector = ''
. ${./../../scripts/Common/Scripts/choose-disk.sh}; . ${./../../scripts/Common/Scripts/choose-disk.sh};
chooseDisk ${diskVarName} "Which disk do you wish to install the OS on?"; chooseDisk ${diskVarName} "Which disk do you wish to install the OS on?";
@ -79,6 +85,7 @@
partition: partition:
let let
inherit (partition) inherit (partition)
format
index index
keepExisting keepExisting
sizeScript sizeScript
@ -89,9 +96,19 @@
${sizeScript} | sed -e "s/.*[^[:space:]]/size=\0/" ${sizeScript} | sed -e "s/.*[^[:space:]]/size=\0/"
''; '';
create = appendScript "${toString index}: \"$(${sizeOption})\" type=${lib.strings.escapeShellArg type}"; formatScripts = {
${fs.ext4} = "mkfs.ext4 -F ${diskVar}";
${fs.ntfs} = "mkfs.ntfs -F ${diskVar}";
${fs.fat32} = "mkfs.fat -F 32 ${diskVar}";
};
create = lib.strings.concatLines [
(appendScript "${toString index}: \"$(${sizeOption})\" type=${lib.strings.escapeShellArg type}")
formatScripts.${format}
];
fallback = '' fallback = ''
if ! { ls "${diskVar}"?(p)${toString partition.index} 2>&1; } > /dev/null if ! { ls "${diskVar}"?(p)${toString index} 2>&1; } > /dev/null
then then
${create} ${create}
fi fi
@ -161,6 +178,11 @@
default = null; default = null;
}; };
format = mkOption {
type = types.enum (builtins.attrValues fs);
description = "The file system format of the partition.";
};
size = mkOption { size = mkOption {
type = types.nullOr types.str; type = types.nullOr types.str;
description = "The size of the partition."; description = "The size of the partition.";
@ -215,17 +237,19 @@
index = 1; index = 1;
type = "uefi"; type = "uefi";
size = "+1G"; size = "+1G";
format = fs.fat32;
}; };
Swap = { Swap = {
index = 2; index = 2;
type = "swap"; type = "swap";
format = fs.ntfs;
}; };
OS = { OS = {
index = 3; index = 3;
type = "linux"; type = "linux";
size = ""; format = fs.ext4;
}; };
}; };
}; };