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}}'';
isSwap = partition: builtins.elem partition.type ["swap" 19];
fs = {
ext4 = "ext4";
ntfs = "ntfs";
fat32 = "fat32";
};
diskSelector = ''
. ${./../../scripts/Common/Scripts/choose-disk.sh};
chooseDisk ${diskVarName} "Which disk do you wish to install the OS on?";
@ -79,6 +85,7 @@
partition:
let
inherit (partition)
format
index
keepExisting
sizeScript
@ -89,9 +96,19 @@
${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 = ''
if ! { ls "${diskVar}"?(p)${toString partition.index} 2>&1; } > /dev/null
if ! { ls "${diskVar}"?(p)${toString index} 2>&1; } > /dev/null
then
${create}
fi
@ -161,6 +178,11 @@
default = null;
};
format = mkOption {
type = types.enum (builtins.attrValues fs);
description = "The file system format of the partition.";
};
size = mkOption {
type = types.nullOr types.str;
description = "The size of the partition.";
@ -215,17 +237,19 @@
index = 1;
type = "uefi";
size = "+1G";
format = fs.fat32;
};
Swap = {
index = 2;
type = "swap";
format = fs.ntfs;
};
OS = {
index = 3;
type = "linux";
size = "";
format = fs.ext4;
};
};
};