diff --git a/lib/modules/partition.nix b/lib/modules/partition.nix index b521cc14..f1428df1 100644 --- a/lib/modules/partition.nix +++ b/lib/modules/partition.nix @@ -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; }; }; };