Refine the sorting of partitions
This commit is contained in:
parent
dc4bcb4d22
commit
5b9a15b03e
1 changed files with 13 additions and 7 deletions
|
@ -3,6 +3,7 @@
|
||||||
inherit (lib) types mkOption;
|
inherit (lib) types mkOption;
|
||||||
diskVarName = "myDisk";
|
diskVarName = "myDisk";
|
||||||
diskVar = ''''${${diskVarName}}'';
|
diskVar = ''''${${diskVarName}}'';
|
||||||
|
isSwap = partition: builtins.elem partition.type ["swap" 19];
|
||||||
|
|
||||||
diskSelector = ''
|
diskSelector = ''
|
||||||
. ${./../../scripts/Common/Scripts/choose-disk.sh};
|
. ${./../../scripts/Common/Scripts/choose-disk.sh};
|
||||||
|
@ -51,7 +52,15 @@
|
||||||
|
|
||||||
config =
|
config =
|
||||||
let
|
let
|
||||||
partitions = lib.lists.sortOn (_: _.order) (builtins.attrValues config.partitions);
|
partitions = builtins.foldl'
|
||||||
|
(list: predicate: lib.lists.sortOn predicate list)
|
||||||
|
(builtins.attrValues config.partitions)
|
||||||
|
[
|
||||||
|
(_: _.index)
|
||||||
|
(_: _.order)
|
||||||
|
(_: if ((!isSwap _) && (_.size == null)) then 1 else 0)
|
||||||
|
];
|
||||||
|
|
||||||
cleanup = lib.strings.concatLines (builtins.map
|
cleanup = lib.strings.concatLines (builtins.map
|
||||||
(partition: ''sudo sfdisk --delete ${diskVar} ${toString partition.index}'')
|
(partition: ''sudo sfdisk --delete ${diskVar} ${toString partition.index}'')
|
||||||
(builtins.filter (_: !_.keepExisting) partitions));
|
(builtins.filter (_: !_.keepExisting) partitions));
|
||||||
|
@ -118,10 +127,7 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
partitionType = types.submodule (
|
partitionType = types.submodule (
|
||||||
{ name, config, ... }:
|
{ name, config, ... }: {
|
||||||
let
|
|
||||||
isSwap = builtins.elem config.type ["swap" 19];
|
|
||||||
in {
|
|
||||||
options = {
|
options = {
|
||||||
index = mkOption {
|
index = mkOption {
|
||||||
type = types.int;
|
type = types.int;
|
||||||
|
@ -131,7 +137,7 @@
|
||||||
order = mkOption {
|
order = mkOption {
|
||||||
type = types.int;
|
type = types.int;
|
||||||
description = "The sort order of the partition creation.";
|
description = "The sort order of the partition creation.";
|
||||||
default = if (!isSwap) && ((builtins.match ".*[^[:space:]].*" (toString config.size)) == null) then 1 else 0;
|
default = if (!(isSwap config)) && ((builtins.match ".*[^[:space:]].*" (toString config.size)) == null) then 1 else 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
label = mkOption {
|
label = mkOption {
|
||||||
|
@ -167,7 +173,7 @@
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
sizeScript = (
|
sizeScript = (
|
||||||
if isSwap
|
if isSwap config
|
||||||
then
|
then
|
||||||
''echo "$(cat /proc/meminfo | awk -F " " '/^MemTotal/ { print $2 }' | awk '{ print int((($1 / 1024 / 1024) * 0.75) + 0.5)}')"G''
|
''echo "$(cat /proc/meminfo | awk -F " " '/^MemTotal/ { print $2 }' | awk '{ print int((($1 / 1024 / 1024) * 0.75) + 0.5)}')"G''
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue