Refactor terminology

This commit is contained in:
Manuel Thalmann 2024-12-07 17:43:53 +01:00
parent 0ce36394ac
commit 68e1990c87
5 changed files with 35 additions and 35 deletions

View file

@ -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

View file

@ -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

View file

@ -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
{

View file

@ -25,7 +25,7 @@
};
};
fileSystems.diskSetup.disks.OS.partitions = {
fileSystems.diskSetup.devices.OS.partitions = {
# Keep Windows' boot partition
Boot.keepExisting = true;

View file

@ -5,7 +5,7 @@ in {
config = {
valhalla = {
fileSystems.diskSetup.disks = {
fileSystems.diskSetup.devices = {
OS = {
partitions = {
Boot = {