From 25ba2fbe8a9bf6a760acbcc296f3bc21f79b919a Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Sat, 7 Dec 2024 17:43:53 +0100 Subject: [PATCH] Refactor terminology --- lib/modules/fileSystems.nix | 8 +-- .../{choose-disk.fish => choose-device.fish} | 2 +- lib/modules/partition/disks.nix | 56 +++++++++---------- profiles/machines/manuel/DerGeret/config.nix | 2 +- profiles/machines/manuel/Generic/config.nix | 2 +- 5 files changed, 35 insertions(+), 35 deletions(-) rename lib/modules/partition/{choose-disk.fish => choose-device.fish} (87%) diff --git a/lib/modules/fileSystems.nix b/lib/modules/fileSystems.nix index 1bd50144..ee892cae 100644 --- a/lib/modules/fileSystems.nix +++ b/lib/modules/fileSystems.nix @@ -22,16 +22,16 @@ in { valhalla = { fileSystems = { script = let - disks = (builtins.attrValues cfg.diskSetup.disks); + devices = (builtins.attrValues cfg.diskSetup.devices); in '' #!/bin/bash set -o errexit ${cfg.diskSetup.scripts.init} - ${lib.strings.concatLines (lib.optionals ((builtins.length disks) > 0) [ + ${lib.strings.concatLines (lib.optionals ((builtins.length devices) > 0) [ ''echo "$(tput setaf 3)=== WARNING ====$(tput sgr0)"'' (''echo "Continuing this script will alter the partitions of '' - + (lib.strings.concatStringsSep ", " (builtins.map (_: "${_.deviceVariable}") (lib.lists.init disks))) - + (if (builtins.length disks) > 1 then " and " else "") + (lib.lists.last disks).deviceVariable + ''"'') + + (lib.strings.concatStringsSep ", " (builtins.map (_: "${_.deviceVariable}") (lib.lists.init devices))) + + (if (builtins.length devices) > 1 then " and " else "") + (lib.lists.last devices).deviceVariable + ''"'') '' if ! fish ${./partition/confirm.fish} "Are you sure you want to continue?" "n"; then exit 1 diff --git a/lib/modules/partition/choose-disk.fish b/lib/modules/partition/choose-device.fish similarity index 87% rename from lib/modules/partition/choose-disk.fish rename to lib/modules/partition/choose-device.fish index 09fa3216..e22dd725 100644 --- a/lib/modules/partition/choose-disk.fish +++ b/lib/modules/partition/choose-device.fish @@ -22,7 +22,7 @@ function chooseDisk -a outFile message selectScript end end - select "$header" "$outFile" "$message" "No valid disk found!" "$(string collect $disks)" false + select "$header" "$outFile" "$message" "No valid device found!" "$(string collect $disks)" false and begin set -l disk (string split -n " " (cat "$outFile")) echo "/dev/$disk[1]" >$outFile diff --git a/lib/modules/partition/disks.nix b/lib/modules/partition/disks.nix index b629df83..651a7699 100644 --- a/lib/modules/partition/disks.nix +++ b/lib/modules/partition/disks.nix @@ -4,7 +4,7 @@ let fs = import ./fs.nix; - diskListVarName = "myDisks"; + deviceListVarName = "myDevices"; isSwap = partition: builtins.elem partition.type [ fs.swap 19 ]; probeScript = builtins.concatStringsSep "\n" [ @@ -12,35 +12,35 @@ let "udevadm trigger" ]; - mkDiskType = types.submodule ( + mkDeviceType = types.submodule ( { config, name, ... }: { options = { id = mkOption { type = types.str; - description = "The internal identifier of the disk."; + description = "The internal identifier of the device."; internal = true; }; wipe = mkOption { type = types.bool; - description = "A value indicating whether the disk should be wiped."; + description = "A value indicating whether the device should be wiped."; default = !(lib.lists.any (_: _.keepExisting) (builtins.attrValues config.partitions)); }; - deviceName = mkOption { + name = mkOption { type = types.nullOr types.str; description = "The name of the device."; default = name; }; - devicePath = mkOption { + path = mkOption { type = types.nullOr types.str; description = "The path to the device."; default = - if config.deviceName == null then + if config.name == null then null else - "/dev/${config.deviceName}"; + "/dev/${config.name}"; }; deviceScript = mkOption { @@ -69,13 +69,13 @@ let config = let - diskVarName = "${diskListVarName}[${config.id}]"; - diskVar = "\${${diskVarName}}"; + deviceVarName = "${deviceListVarName}[${config.id}]"; + deviceVar = "\${${deviceVarName}}"; - diskSelector = '' + deviceSelector = '' result="$(mktemp)" - fish ${./choose-disk.fish} "$result" "Please specify the \"${name}\" disk:" ${./select.fish} - ${diskVarName}="$(cat "$result")" + fish ${./choose-device.fish} "$result" "Please select the \"${name}\" device:" ${./select.fish} + ${deviceVarName}="$(cat "$result")" ''; partitions = lib.lists.sortOn (_: _.index) @@ -95,13 +95,13 @@ let "echo ${script} | ${ fdiskCommand "${builtins.concatStringsSep " " args} ${ if append then "--append" else "" - } ${diskVar}" + } ${deviceVar}" }"; wipeScript = script: fdiskScript script [ ] false; appendScript = index: script: fdiskScript script [ "-N" (builtins.toString index) ] true; cleanup = lib.strings.concatLines (builtins.map - (partition: "${fdiskCommand "--delete ${diskVar} ${toString partition.index}"} || true") + (partition: "${fdiskCommand "--delete ${deviceVar} ${toString partition.index}"} || true") (lib.lists.sortOn (partition: partition.index * -1) (builtins.filter (_: !_.keepExisting) partitions))); @@ -151,7 +151,7 @@ let ''; in [ - ''local diskPath="$(find -L /dev/disk/by-diskseq -samefile ${diskVar})"'' + ''local diskPath="$(find -L /dev/disk/by-diskseq -samefile ${deviceVar})"'' ''local ${partVarName}="$diskPath-part${toString index}"'' (if keepExisting then fallback else create) "sudo ${labelScripts.${format} label}" @@ -164,24 +164,24 @@ let partition: lib.optional (partition.keepExisting && !(builtins.isNull partition.type)) - ''sudo sfdisk --part-type ${diskVar} ${toString partition.index} ${mkType partition.type}'' + ''sudo sfdisk --part-type ${deviceVar} ${toString partition.index} ${mkType partition.type}'' ) partitions); in { id = "disk-${name}"; - deviceVariable = diskVar; + deviceVariable = deviceVar; deviceScript = - if config.devicePath == null then '' - ${diskSelector} + if config.path == null then '' + ${deviceSelector} '' else '' - ${diskVarName}=${config.devicePath} - if [ ! -b ${diskVar} ]; then + ${deviceVarName}=${config.path} + if [ ! -b ${deviceVar} ]; then function fallback() { - echo "Couldn't find the specified disk \"${diskVar}\"." + echo "Couldn't find the specified disk \"${deviceVar}\"." if fish ${./confirm.fish} "Do you want to choose a different \"${name}\" disk?"; then - ${diskSelector} + ${deviceSelector} else exit 1 fi @@ -292,9 +292,9 @@ in }; diskSetup = { - disks = mkOption { - type = types.attrsOf (mkDiskType); - description = "The additional disks to format."; + devices = mkOption { + type = types.attrsOf (mkDeviceType); + description = "The disk devices to format."; default = { }; }; @@ -328,7 +328,7 @@ in inherit (cfg) rootDir; inherit (lib.strings) normalizePath; partPath = part: "/dev/disk/by-label/${part.label}"; - disks = ((builtins.attrValues cfg.diskSetup.disks)); + disks = ((builtins.attrValues cfg.diskSetup.devices)); partitions = (builtins.concatMap (_: (builtins.attrValues _.partitions)) disks); in { diff --git a/profiles/machines/manuel/DerGeret/config.nix b/profiles/machines/manuel/DerGeret/config.nix index 55facd7e..38edca9f 100644 --- a/profiles/machines/manuel/DerGeret/config.nix +++ b/profiles/machines/manuel/DerGeret/config.nix @@ -25,7 +25,7 @@ }; }; - fileSystems.diskSetup.disks.OS.partitions = { + fileSystems.diskSetup.devices.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 6054c5f2..a2e22c44 100644 --- a/profiles/machines/manuel/Generic/config.nix +++ b/profiles/machines/manuel/Generic/config.nix @@ -5,7 +5,7 @@ in { config = { valhalla = { - fileSystems.diskSetup.disks = { + fileSystems.diskSetup.devices = { OS = { partitions = { Boot = {