tidy: move relevant variables and format script block

This commit is contained in:
dylan madisetti 2024-08-01 15:59:33 -04:00
parent b2a106f8ed
commit 6bebcc728e
No known key found for this signature in database
GPG key ID: 9080F46A6E933A9D

View file

@ -7,13 +7,6 @@ let
"raidz2"
"raidz3"
];
format_output = (mode: members: ''
entries+=("${mode}=${
lib.concatMapStringsSep " "
(d: "/dev/disk/by-partlabel/disk-${d}-zfs") members
}")
'');
format_vdev = (vdev: format_output vdev.mode vdev.members);
in
{
options = {
@ -119,7 +112,18 @@ in
};
_create = diskoLib.mkCreateOption {
inherit config options;
default = ''
default =
let
format_output = (mode: members: ''
entries+=("${mode}=${
lib.concatMapStringsSep " "
(d: "/dev/disk/by-partlabel/disk-${d}-zfs") members
}")
'');
format_vdev = (vdev: format_output vdev.mode vdev.members);
hasTopology = config.topology != null;
in
''
readarray -t zfs_devices < <(cat "$disko_devices_dir"/zfs_${config.name})
# Try importing the pool without mounting anything if it exists.
# This allows us to set mounpoints.
@ -147,7 +151,7 @@ in
# For shell check
mode="${config.mode}"
if [ $mode != "prescribed" ]; then
${if config.topology == null then
${if hasTopology then
''topology="${config.mode} \"''${zfs_devices}\""''
else
''
@ -157,10 +161,11 @@ in
}
else
entries=()
${lib.concatMapStrings format_vdev config.topology.vdev}
${lib.optionalString (config.topology.special != null)
${lib.optionalString (hasTopology && config.topology.vdev != null)
(lib.concatMapStrings format_vdev config.topology.vdev)}
${lib.optionalString (hasTopology && config.topology.special != null)
(format_output "special ${config.topology.special.mode}" config.topology.special.members)}
${lib.optionalString (config.topology.cache != null)
${lib.optionalString (hasTopology && config.topology.cache != null)
(format_output "cache" [config.topology.cache])}
all_devices=()
for line in "''${entries[@]}"; do