tidy: move relevant variables and format script block

This commit is contained in:
dylan madisetti committed 2024-08-01 15:59:33 -04:00
1 parent b2a106f8ed
commit 6bebcc728e
1 file changed
+17 -12
+17 -12
View File
@@ -7,13 +7,6 @@ let
"raidz2" "raidz2"
"raidz3" "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 in
{ {
options = { options = {
@@ -119,7 +112,18 @@ in
}; };
_create = diskoLib.mkCreateOption { _create = diskoLib.mkCreateOption {
inherit config options; 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}) readarray -t zfs_devices < <(cat "$disko_devices_dir"/zfs_${config.name})
# Try importing the pool without mounting anything if it exists. # Try importing the pool without mounting anything if it exists.
# This allows us to set mounpoints. # This allows us to set mounpoints.
@@ -147,7 +151,7 @@ in
# For shell check # For shell check
mode="${config.mode}" mode="${config.mode}"
if [ $mode != "prescribed" ]; then if [ $mode != "prescribed" ]; then
${if config.topology == null then ${if hasTopology then
''topology="${config.mode} \"''${zfs_devices}\""'' ''topology="${config.mode} \"''${zfs_devices}\""''
else else
'' ''
@@ -157,10 +161,11 @@ in
} }
else else
entries=() entries=()
${lib.concatMapStrings format_vdev config.topology.vdev} ${lib.optionalString (hasTopology && config.topology.vdev != null)
${lib.optionalString (config.topology.special != 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)} (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])} (format_output "cache" [config.topology.cache])}
all_devices=() all_devices=()
for line in "''${entries[@]}"; do for line in "''${entries[@]}"; do