mirror of
https://github.com/TECHNOFAB11/disko.git
synced 2025-12-11 23:50:05 +01:00
lib: better formatting of generated shell output
This commit is contained in:
parent
5333c4034a
commit
c9c2fa9d3a
14 changed files with 72 additions and 60 deletions
|
|
@ -5,35 +5,29 @@
|
||||||
type = "disk";
|
type = "disk";
|
||||||
device = builtins.elemAt disks 0;
|
device = builtins.elemAt disks 0;
|
||||||
content = {
|
content = {
|
||||||
type = "table";
|
type = "gpt";
|
||||||
format = "gpt";
|
partitions = {
|
||||||
partitions = [
|
ESP = {
|
||||||
{
|
|
||||||
name = "ESP";
|
|
||||||
start = "1MiB";
|
start = "1MiB";
|
||||||
end = "128MiB";
|
end = "128MiB";
|
||||||
fs-type = "fat32";
|
|
||||||
bootable = true;
|
|
||||||
content = {
|
content = {
|
||||||
type = "filesystem";
|
type = "filesystem";
|
||||||
format = "vfat";
|
format = "vfat";
|
||||||
mountpoint = "/boot";
|
mountpoint = "/boot";
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
];
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
disk1 = {
|
disk1 = {
|
||||||
type = "disk";
|
type = "disk";
|
||||||
device = builtins.elemAt disks 1;
|
device = builtins.elemAt disks 1;
|
||||||
content = {
|
content = {
|
||||||
type = "table";
|
type = "gpt";
|
||||||
format = "gpt";
|
partitions = {
|
||||||
partitions = [
|
luks = {
|
||||||
{
|
|
||||||
start = "1M";
|
start = "1M";
|
||||||
end = "100%";
|
size = "100%";
|
||||||
name = "luks";
|
|
||||||
content = {
|
content = {
|
||||||
type = "luks";
|
type = "luks";
|
||||||
name = "crypted1";
|
name = "crypted1";
|
||||||
|
|
@ -46,21 +40,19 @@
|
||||||
vg = "pool";
|
vg = "pool";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
];
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
disk2 = {
|
disk2 = {
|
||||||
type = "disk";
|
type = "disk";
|
||||||
device = builtins.elemAt disks 2;
|
device = builtins.elemAt disks 2;
|
||||||
content = {
|
content = {
|
||||||
type = "table";
|
type = "gpt";
|
||||||
format = "gpt";
|
partitions = {
|
||||||
partitions = [
|
luks = {
|
||||||
{
|
|
||||||
start = "1M";
|
start = "1M";
|
||||||
end = "100%";
|
size = "100%";
|
||||||
name = "luks";
|
|
||||||
content = {
|
content = {
|
||||||
type = "luks";
|
type = "luks";
|
||||||
name = "crypted2";
|
name = "crypted2";
|
||||||
|
|
@ -73,8 +65,8 @@
|
||||||
vg = "pool";
|
vg = "pool";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
];
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -83,20 +75,18 @@
|
||||||
type = "mdadm";
|
type = "mdadm";
|
||||||
level = 1;
|
level = 1;
|
||||||
content = {
|
content = {
|
||||||
type = "table";
|
type = "gpt";
|
||||||
format = "gpt";
|
partitions = {
|
||||||
partitions = [
|
bla = {
|
||||||
{
|
|
||||||
name = "bla";
|
|
||||||
start = "1MiB";
|
start = "1MiB";
|
||||||
end = "100%";
|
size = "100%";
|
||||||
content = {
|
content = {
|
||||||
type = "filesystem";
|
type = "filesystem";
|
||||||
format = "ext4";
|
format = "ext4";
|
||||||
mountpoint = "/ext4_mdadm_lvm";
|
mountpoint = "/ext4_mdadm_lvm";
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
];
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,17 @@ let
|
||||||
in
|
in
|
||||||
iter 1 list;
|
iter 1 list;
|
||||||
|
|
||||||
|
|
||||||
|
/* indent takes a multiline string and indents it by 2 spaces starting on the second line
|
||||||
|
|
||||||
|
indent :: str -> str
|
||||||
|
|
||||||
|
Example:
|
||||||
|
indent "test\nbla"
|
||||||
|
=> "test\n bla"
|
||||||
|
*/
|
||||||
|
indent = replaceStrings ["\n"] ["\n "];
|
||||||
|
|
||||||
/* A nix option type representing a json datastructure, vendored from nixpkgs to avoid dependency on pkgs */
|
/* A nix option type representing a json datastructure, vendored from nixpkgs to avoid dependency on pkgs */
|
||||||
jsonType =
|
jsonType =
|
||||||
let
|
let
|
||||||
|
|
@ -203,10 +214,10 @@ let
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = lib.types.str;
|
type = lib.types.str;
|
||||||
default = ''
|
default = ''
|
||||||
( # ${config.type} ${concatMapStringsSep " " (n: toString (config.${n} or "")) ["name" "device" "format" "mountpoint"]}
|
( # ${config.type} ${concatMapStringsSep " " (n: toString (config.${n} or "")) ["name" "device" "format" "mountpoint"]} #
|
||||||
${diskoLib.defineHookVariables { inherit config options; }}
|
${diskoLib.indent (diskoLib.defineHookVariables { inherit config options; })}
|
||||||
${config.preCreateHook}
|
${config.preCreateHook}
|
||||||
${attrs.default}
|
${diskoLib.indent attrs.default}
|
||||||
${config.postCreateHook}
|
${config.postCreateHook}
|
||||||
)
|
)
|
||||||
'';
|
'';
|
||||||
|
|
@ -228,7 +239,10 @@ let
|
||||||
*/
|
*/
|
||||||
writeCheckedBash = { pkgs, checked ? false, noDeps ? false }: pkgs.writers.makeScriptWriter {
|
writeCheckedBash = { pkgs, checked ? false, noDeps ? false }: pkgs.writers.makeScriptWriter {
|
||||||
interpreter = if noDeps then "/usr/bin/env bash" else "${pkgs.bash}/bin/bash";
|
interpreter = if noDeps then "/usr/bin/env bash" else "${pkgs.bash}/bin/bash";
|
||||||
check = lib.optionalString checked "${pkgs.shellcheck}/bin/shellcheck -e SC2034";
|
check = lib.optionalString checked (pkgs.writeScript "check" ''
|
||||||
|
set -efu
|
||||||
|
${pkgs.shellcheck}/bin/shellcheck -e SC2034 "$1"
|
||||||
|
'');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,8 @@ in
|
||||||
--typecode=${toString partition._index}:${partition.type} \
|
--typecode=${toString partition._index}:${partition.type} \
|
||||||
${config.device}
|
${config.device}
|
||||||
# ensure /dev/disk/by-path/..-partN exists before continuing
|
# ensure /dev/disk/by-path/..-partN exists before continuing
|
||||||
udevadm trigger --subsystem-match=block; udevadm settle
|
udevadm trigger --subsystem-match=block
|
||||||
|
udevadm settle
|
||||||
${lib.optionalString (partition.content != null) partition.content._create}
|
${lib.optionalString (partition.content != null) partition.content._create}
|
||||||
'') sortedPartitions)}
|
'') sortedPartitions)}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,9 @@
|
||||||
inherit config options;
|
inherit config options;
|
||||||
default = ''
|
default = ''
|
||||||
cryptsetup -q luksFormat ${config.device} ${diskoLib.maybeStr config.keyFile} ${toString config.extraFormatArgs}
|
cryptsetup -q luksFormat ${config.device} ${diskoLib.maybeStr config.keyFile} ${toString config.extraFormatArgs}
|
||||||
cryptsetup luksOpen ${config.device} ${config.name} ${toString config.extraOpenArgs} ${lib.optionalString (config.keyFile != null) "--key-file ${config.keyFile}"}
|
cryptsetup luksOpen ${config.device} ${config.name} \
|
||||||
|
${toString config.extraOpenArgs} \
|
||||||
|
${lib.optionalString (config.keyFile != null) "--key-file ${config.keyFile}"}
|
||||||
${lib.optionalString (config.content != null) config.content._create}
|
${lib.optionalString (config.content != null) config.content._create}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,8 @@
|
||||||
--force \
|
--force \
|
||||||
--homehost=any \
|
--homehost=any \
|
||||||
"''${disk_devices[@]}"
|
"''${disk_devices[@]}"
|
||||||
udevadm trigger --subsystem-match=block; udevadm settle
|
udevadm trigger --subsystem-match=block
|
||||||
|
udevadm settle
|
||||||
${lib.optionalString (config.content != null) config.content._create}
|
${lib.optionalString (config.content != null) config.content._create}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,8 @@
|
||||||
parted -s ${config.device} -- mkpart ${partition.part-type} ${diskoLib.maybeStr partition.fs-type} ${diskoLib.maybeStr partition.fs-type} ${partition.start} ${partition.end}
|
parted -s ${config.device} -- mkpart ${partition.part-type} ${diskoLib.maybeStr partition.fs-type} ${diskoLib.maybeStr partition.fs-type} ${partition.start} ${partition.end}
|
||||||
''}
|
''}
|
||||||
# ensure /dev/disk/by-path/..-partN exists before continuing
|
# ensure /dev/disk/by-path/..-partN exists before continuing
|
||||||
udevadm trigger --subsystem-match=block; udevadm settle
|
udevadm trigger --subsystem-match=block
|
||||||
|
udevadm settle
|
||||||
${lib.optionalString partition.bootable ''
|
${lib.optionalString partition.bootable ''
|
||||||
parted -s ${config.device} -- set ${toString partition._index} boot on
|
parted -s ${config.device} -- set ${toString partition._index} boot on
|
||||||
''}
|
''}
|
||||||
|
|
@ -99,7 +100,8 @@
|
||||||
parted -s ${config.device} -- set ${toString partition._index} ${flag} on
|
parted -s ${config.device} -- set ${toString partition._index} ${flag} on
|
||||||
'') partition.flags}
|
'') partition.flags}
|
||||||
# ensure further operations can detect new partitions
|
# ensure further operations can detect new partitions
|
||||||
udevadm trigger --subsystem-match=block; udevadm settle
|
udevadm trigger --subsystem-match=block
|
||||||
|
udevadm settle
|
||||||
${lib.optionalString (partition.content != null) partition.content._create}
|
${lib.optionalString (partition.content != null) partition.content._create}
|
||||||
'') config.partitions)}
|
'') config.partitions)}
|
||||||
'';
|
'';
|
||||||
|
|
|
||||||
|
|
@ -48,8 +48,10 @@
|
||||||
inherit config options;
|
inherit config options;
|
||||||
default = ''
|
default = ''
|
||||||
zfs create ${config._parent.name}/${config.name} \
|
zfs create ${config._parent.name}/${config.name} \
|
||||||
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") config.options)} -V ${config.size}
|
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") config.options)} \
|
||||||
udevadm trigger --subsystem-match=block; udevadm settle
|
-V ${config.size}
|
||||||
|
udevadm trigger --subsystem-match=block
|
||||||
|
udevadm settle
|
||||||
${lib.optionalString (config.content != null) config.content._create}
|
${lib.optionalString (config.content != null) config.content._create}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
dev = ''
|
dev = ''
|
||||||
zpool list '${config.name}' >/dev/null 2>/dev/null || \
|
zpool list '${config.name}' >/dev/null 2>/dev/null ||
|
||||||
zpool import -l -R ${config.mountRoot} '${config.name}'
|
zpool import -l -R ${config.mountRoot} '${config.name}'
|
||||||
${lib.concatMapStrings (x: x.dev or "") (lib.attrValues datasetMounts)}
|
${lib.concatMapStrings (x: x.dev or "") (lib.attrValues datasetMounts)}
|
||||||
'';
|
'';
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue