From 127ac0688fb834a01836f9def8bc0e5c6ec99292 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Sat, 7 Dec 2024 16:11:19 +0100 Subject: [PATCH] Remove separate os disk declaration --- lib/modules/partition/disks.nix | 53 ++++++++------------ profiles/machines/manuel/DerGeret/config.nix | 2 +- profiles/machines/manuel/Generic/config.nix | 4 +- profiles/machines/manuel/server.nix | 4 +- 4 files changed, 25 insertions(+), 38 deletions(-) diff --git a/lib/modules/partition/disks.nix b/lib/modules/partition/disks.nix index ce726fb7..2a2c580c 100644 --- a/lib/modules/partition/disks.nix +++ b/lib/modules/partition/disks.nix @@ -12,7 +12,7 @@ let "udevadm trigger" ]; - mkDiskType = osDisk: types.submodule ( + mkDiskType = types.submodule ( { config, name, ... }: { options = { id = mkOption { @@ -30,18 +30,14 @@ let deviceName = mkOption { type = types.nullOr types.str; description = "The name of the device."; - default = if osDisk then null else name; + default = name; }; devicePath = mkOption { - type = - if osDisk then - types.nullOr types.str - else - types.str; + type = types.nullOr types.str; description = "The path to the device."; default = - if osDisk && config.deviceName == null then + if config.deviceName == null then null else "/dev/${config.deviceName}"; @@ -78,7 +74,7 @@ let diskSelector = '' result="$(mktemp)" - fish ${./choose-disk.fish} "$result" "Which disk do you wish to install the OS on?" ${./select.fish} + fish ${./choose-disk.fish} "$result" "Please specify the \"${name}\" disk:" ${./select.fish} ${diskVarName}="$(cat "$result")" ''; @@ -173,29 +169,26 @@ let partitions); in { - id = if osDisk then "os" else "disk-${name}"; + id = "disk-${name}"; deviceVariable = diskVar; deviceScript = - if osDisk && config.devicePath == null then '' + if config.devicePath == null then '' ${diskSelector} '' else '' ${diskVarName}=${config.devicePath} - ${if osDisk then '' - if [ ! -b ${diskVar} ]; then - function fallback() { - echo "Couldn't find the specified disk \"${diskVar}\"." - if fish ${./confirm.fish} "Do you want to install the OS on another disk?"; then - ${diskSelector} - else - exit 1 - fi - } + if [ ! -b ${diskVar} ]; then + function fallback() { + echo "Couldn't find the specified disk \"${diskVar}\"." + if fish ${./confirm.fish} "Do you want to choose a different \"${name}\" disk?"; then + ${diskSelector} + else + exit 1 + fi + } - fallback - fi - '' else - ""} + fallback + fi ''; script = lib.mkDefault '' @@ -299,13 +292,8 @@ in }; diskSetup = { - osDisk = mkOption { - type = mkDiskType true; - description = "The partition layout of the OS disk."; - }; - disks = mkOption { - type = types.attrsOf (mkDiskType false); + type = types.attrsOf (mkDiskType); description = "The additional disks to format."; default = { }; }; @@ -326,10 +314,9 @@ in let cfg = config.valhalla.fileSystems; inherit (cfg) rootDir; - inherit (cfg.diskSetup) osDisk; inherit (lib.strings) normalizePath; partPath = part: "/dev/disk/by-label/${part.label}"; - disks = ([ osDisk ] ++ (builtins.attrValues cfg.diskSetup.disks)); + disks = ((builtins.attrValues cfg.diskSetup.disks)); partitions = (builtins.concatMap (_: (builtins.attrValues _.partitions)) disks); mountScript = lib.strings.concatLines (builtins.concatMap diff --git a/profiles/machines/manuel/DerGeret/config.nix b/profiles/machines/manuel/DerGeret/config.nix index 01422c85..55facd7e 100644 --- a/profiles/machines/manuel/DerGeret/config.nix +++ b/profiles/machines/manuel/DerGeret/config.nix @@ -25,7 +25,7 @@ }; }; - fileSystems.diskSetup.osDisk.partitions = { + fileSystems.diskSetup.disks.OS.partitions = { # Keep Windows' boot partition Boot.keepExisting = true; diff --git a/profiles/machines/manuel/Generic/config.nix b/profiles/machines/manuel/Generic/config.nix index 379a72b9..6054c5f2 100644 --- a/profiles/machines/manuel/Generic/config.nix +++ b/profiles/machines/manuel/Generic/config.nix @@ -5,8 +5,8 @@ in { config = { valhalla = { - fileSystems.diskSetup = { - osDisk = { + fileSystems.diskSetup.disks = { + OS = { partitions = { Boot = { index = 1; diff --git a/profiles/machines/manuel/server.nix b/profiles/machines/manuel/server.nix index b245d3bf..a18d755c 100644 --- a/profiles/machines/manuel/server.nix +++ b/profiles/machines/manuel/server.nix @@ -5,8 +5,8 @@ in { config = { valhalla = { - fileSystems.diskSetup = { - osDisk = { + fileSystems.diskSetup.disks = { + OS = { partitions = { Boot = { index = 1;