Refactor terminology
This commit is contained in:
parent
b62f3e13c7
commit
25ba2fbe8a
5 changed files with 35 additions and 35 deletions
|
@ -22,16 +22,16 @@ in {
|
||||||
valhalla = {
|
valhalla = {
|
||||||
fileSystems = {
|
fileSystems = {
|
||||||
script = let
|
script = let
|
||||||
disks = (builtins.attrValues cfg.diskSetup.disks);
|
devices = (builtins.attrValues cfg.diskSetup.devices);
|
||||||
in ''
|
in ''
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -o errexit
|
set -o errexit
|
||||||
${cfg.diskSetup.scripts.init}
|
${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 "$(tput setaf 3)=== WARNING ====$(tput sgr0)"''
|
||||||
(''echo "Continuing this script will alter the partitions of ''
|
(''echo "Continuing this script will alter the partitions of ''
|
||||||
+ (lib.strings.concatStringsSep ", " (builtins.map (_: "${_.deviceVariable}") (lib.lists.init disks)))
|
+ (lib.strings.concatStringsSep ", " (builtins.map (_: "${_.deviceVariable}") (lib.lists.init devices)))
|
||||||
+ (if (builtins.length disks) > 1 then " and " else "") + (lib.lists.last disks).deviceVariable + ''"'')
|
+ (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
|
if ! fish ${./partition/confirm.fish} "Are you sure you want to continue?" "n"; then
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
@ -22,7 +22,7 @@ function chooseDisk -a outFile message selectScript
|
||||||
end
|
end
|
||||||
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
|
and begin
|
||||||
set -l disk (string split -n " " (cat "$outFile"))
|
set -l disk (string split -n " " (cat "$outFile"))
|
||||||
echo "/dev/$disk[1]" >$outFile
|
echo "/dev/$disk[1]" >$outFile
|
|
@ -4,7 +4,7 @@ let
|
||||||
|
|
||||||
fs = import ./fs.nix;
|
fs = import ./fs.nix;
|
||||||
|
|
||||||
diskListVarName = "myDisks";
|
deviceListVarName = "myDevices";
|
||||||
isSwap = partition: builtins.elem partition.type [ fs.swap 19 ];
|
isSwap = partition: builtins.elem partition.type [ fs.swap 19 ];
|
||||||
|
|
||||||
probeScript = builtins.concatStringsSep "\n" [
|
probeScript = builtins.concatStringsSep "\n" [
|
||||||
|
@ -12,35 +12,35 @@ let
|
||||||
"udevadm trigger"
|
"udevadm trigger"
|
||||||
];
|
];
|
||||||
|
|
||||||
mkDiskType = types.submodule (
|
mkDeviceType = types.submodule (
|
||||||
{ config, name, ... }: {
|
{ config, name, ... }: {
|
||||||
options = {
|
options = {
|
||||||
id = mkOption {
|
id = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
description = "The internal identifier of the disk.";
|
description = "The internal identifier of the device.";
|
||||||
internal = true;
|
internal = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
wipe = mkOption {
|
wipe = mkOption {
|
||||||
type = types.bool;
|
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));
|
default = !(lib.lists.any (_: _.keepExisting) (builtins.attrValues config.partitions));
|
||||||
};
|
};
|
||||||
|
|
||||||
deviceName = mkOption {
|
name = mkOption {
|
||||||
type = types.nullOr types.str;
|
type = types.nullOr types.str;
|
||||||
description = "The name of the device.";
|
description = "The name of the device.";
|
||||||
default = name;
|
default = name;
|
||||||
};
|
};
|
||||||
|
|
||||||
devicePath = mkOption {
|
path = mkOption {
|
||||||
type = types.nullOr types.str;
|
type = types.nullOr types.str;
|
||||||
description = "The path to the device.";
|
description = "The path to the device.";
|
||||||
default =
|
default =
|
||||||
if config.deviceName == null then
|
if config.name == null then
|
||||||
null
|
null
|
||||||
else
|
else
|
||||||
"/dev/${config.deviceName}";
|
"/dev/${config.name}";
|
||||||
};
|
};
|
||||||
|
|
||||||
deviceScript = mkOption {
|
deviceScript = mkOption {
|
||||||
|
@ -69,13 +69,13 @@ let
|
||||||
|
|
||||||
config =
|
config =
|
||||||
let
|
let
|
||||||
diskVarName = "${diskListVarName}[${config.id}]";
|
deviceVarName = "${deviceListVarName}[${config.id}]";
|
||||||
diskVar = "\${${diskVarName}}";
|
deviceVar = "\${${deviceVarName}}";
|
||||||
|
|
||||||
diskSelector = ''
|
deviceSelector = ''
|
||||||
result="$(mktemp)"
|
result="$(mktemp)"
|
||||||
fish ${./choose-disk.fish} "$result" "Please specify the \"${name}\" disk:" ${./select.fish}
|
fish ${./choose-device.fish} "$result" "Please select the \"${name}\" device:" ${./select.fish}
|
||||||
${diskVarName}="$(cat "$result")"
|
${deviceVarName}="$(cat "$result")"
|
||||||
'';
|
'';
|
||||||
|
|
||||||
partitions = lib.lists.sortOn (_: _.index)
|
partitions = lib.lists.sortOn (_: _.index)
|
||||||
|
@ -95,13 +95,13 @@ let
|
||||||
"echo ${script} | ${
|
"echo ${script} | ${
|
||||||
fdiskCommand "${builtins.concatStringsSep " " args} ${
|
fdiskCommand "${builtins.concatStringsSep " " args} ${
|
||||||
if append then "--append" else ""
|
if append then "--append" else ""
|
||||||
} ${diskVar}"
|
} ${deviceVar}"
|
||||||
}";
|
}";
|
||||||
wipeScript = script: fdiskScript script [ ] false;
|
wipeScript = script: fdiskScript script [ ] false;
|
||||||
appendScript = index: script: fdiskScript script [ "-N" (builtins.toString index) ] true;
|
appendScript = index: script: fdiskScript script [ "-N" (builtins.toString index) ] true;
|
||||||
|
|
||||||
cleanup = lib.strings.concatLines (builtins.map
|
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
|
(lib.lists.sortOn
|
||||||
(partition: partition.index * -1)
|
(partition: partition.index * -1)
|
||||||
(builtins.filter (_: !_.keepExisting) partitions)));
|
(builtins.filter (_: !_.keepExisting) partitions)));
|
||||||
|
@ -151,7 +151,7 @@ let
|
||||||
'';
|
'';
|
||||||
in
|
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}"''
|
''local ${partVarName}="$diskPath-part${toString index}"''
|
||||||
(if keepExisting then fallback else create)
|
(if keepExisting then fallback else create)
|
||||||
"sudo ${labelScripts.${format} label}"
|
"sudo ${labelScripts.${format} label}"
|
||||||
|
@ -164,24 +164,24 @@ let
|
||||||
partition:
|
partition:
|
||||||
lib.optional
|
lib.optional
|
||||||
(partition.keepExisting && !(builtins.isNull partition.type))
|
(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);
|
partitions);
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
id = "disk-${name}";
|
id = "disk-${name}";
|
||||||
deviceVariable = diskVar;
|
deviceVariable = deviceVar;
|
||||||
|
|
||||||
deviceScript =
|
deviceScript =
|
||||||
if config.devicePath == null then ''
|
if config.path == null then ''
|
||||||
${diskSelector}
|
${deviceSelector}
|
||||||
'' else ''
|
'' else ''
|
||||||
${diskVarName}=${config.devicePath}
|
${deviceVarName}=${config.path}
|
||||||
if [ ! -b ${diskVar} ]; then
|
if [ ! -b ${deviceVar} ]; then
|
||||||
function fallback() {
|
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
|
if fish ${./confirm.fish} "Do you want to choose a different \"${name}\" disk?"; then
|
||||||
${diskSelector}
|
${deviceSelector}
|
||||||
else
|
else
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
@ -292,9 +292,9 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
diskSetup = {
|
diskSetup = {
|
||||||
disks = mkOption {
|
devices = mkOption {
|
||||||
type = types.attrsOf (mkDiskType);
|
type = types.attrsOf (mkDeviceType);
|
||||||
description = "The additional disks to format.";
|
description = "The disk devices to format.";
|
||||||
default = { };
|
default = { };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -328,7 +328,7 @@ in
|
||||||
inherit (cfg) rootDir;
|
inherit (cfg) rootDir;
|
||||||
inherit (lib.strings) normalizePath;
|
inherit (lib.strings) normalizePath;
|
||||||
partPath = part: "/dev/disk/by-label/${part.label}";
|
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);
|
partitions = (builtins.concatMap (_: (builtins.attrValues _.partitions)) disks);
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
fileSystems.diskSetup.disks.OS.partitions = {
|
fileSystems.diskSetup.devices.OS.partitions = {
|
||||||
# Keep Windows' boot partition
|
# Keep Windows' boot partition
|
||||||
Boot.keepExisting = true;
|
Boot.keepExisting = true;
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ in {
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
valhalla = {
|
valhalla = {
|
||||||
fileSystems.diskSetup.disks = {
|
fileSystems.diskSetup.devices = {
|
||||||
OS = {
|
OS = {
|
||||||
partitions = {
|
partitions = {
|
||||||
Boot = {
|
Boot = {
|
||||||
|
|
Loading…
Reference in a new issue