mirror of
https://github.com/nix-community/disko
synced 2024-11-10 06:14:14 +00: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";
|
||||
device = builtins.elemAt disks 0;
|
||||
content = {
|
||||
type = "table";
|
||||
format = "gpt";
|
||||
partitions = [
|
||||
{
|
||||
name = "ESP";
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
ESP = {
|
||||
start = "1MiB";
|
||||
end = "128MiB";
|
||||
fs-type = "fat32";
|
||||
bootable = true;
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "vfat";
|
||||
mountpoint = "/boot";
|
||||
};
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
disk1 = {
|
||||
type = "disk";
|
||||
device = builtins.elemAt disks 1;
|
||||
content = {
|
||||
type = "table";
|
||||
format = "gpt";
|
||||
partitions = [
|
||||
{
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
luks = {
|
||||
start = "1M";
|
||||
end = "100%";
|
||||
name = "luks";
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "luks";
|
||||
name = "crypted1";
|
||||
|
@ -46,21 +40,19 @@
|
|||
vg = "pool";
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
disk2 = {
|
||||
type = "disk";
|
||||
device = builtins.elemAt disks 2;
|
||||
content = {
|
||||
type = "table";
|
||||
format = "gpt";
|
||||
partitions = [
|
||||
{
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
luks = {
|
||||
start = "1M";
|
||||
end = "100%";
|
||||
name = "luks";
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "luks";
|
||||
name = "crypted2";
|
||||
|
@ -73,8 +65,8 @@
|
|||
vg = "pool";
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
@ -83,20 +75,18 @@
|
|||
type = "mdadm";
|
||||
level = 1;
|
||||
content = {
|
||||
type = "table";
|
||||
format = "gpt";
|
||||
partitions = [
|
||||
{
|
||||
name = "bla";
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
bla = {
|
||||
start = "1MiB";
|
||||
end = "100%";
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "ext4";
|
||||
mountpoint = "/ext4_mdadm_lvm";
|
||||
};
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
@ -98,6 +98,17 @@ let
|
|||
in
|
||||
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 */
|
||||
jsonType =
|
||||
let
|
||||
|
@ -203,10 +214,10 @@ let
|
|||
readOnly = true;
|
||||
type = lib.types.str;
|
||||
default = ''
|
||||
( # ${config.type} ${concatMapStringsSep " " (n: toString (config.${n} or "")) ["name" "device" "format" "mountpoint"]}
|
||||
${diskoLib.defineHookVariables { inherit config options; }}
|
||||
( # ${config.type} ${concatMapStringsSep " " (n: toString (config.${n} or "")) ["name" "device" "format" "mountpoint"]} #
|
||||
${diskoLib.indent (diskoLib.defineHookVariables { inherit config options; })}
|
||||
${config.preCreateHook}
|
||||
${attrs.default}
|
||||
${diskoLib.indent attrs.default}
|
||||
${config.postCreateHook}
|
||||
)
|
||||
'';
|
||||
|
@ -228,7 +239,10 @@ let
|
|||
*/
|
||||
writeCheckedBash = { pkgs, checked ? false, noDeps ? false }: pkgs.writers.makeScriptWriter {
|
||||
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} \
|
||||
${config.device}
|
||||
# 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}
|
||||
'') sortedPartitions)}
|
||||
|
||||
|
|
|
@ -55,7 +55,9 @@
|
|||
inherit config options;
|
||||
default = ''
|
||||
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}
|
||||
'';
|
||||
};
|
||||
|
|
|
@ -42,7 +42,8 @@
|
|||
--force \
|
||||
--homehost=any \
|
||||
"''${disk_devices[@]}"
|
||||
udevadm trigger --subsystem-match=block; udevadm settle
|
||||
udevadm trigger --subsystem-match=block
|
||||
udevadm settle
|
||||
${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}
|
||||
''}
|
||||
# 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 ''
|
||||
parted -s ${config.device} -- set ${toString partition._index} boot on
|
||||
''}
|
||||
|
@ -99,7 +100,8 @@
|
|||
parted -s ${config.device} -- set ${toString partition._index} ${flag} on
|
||||
'') partition.flags}
|
||||
# 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}
|
||||
'') config.partitions)}
|
||||
'';
|
||||
|
|
|
@ -48,8 +48,10 @@
|
|||
inherit config options;
|
||||
default = ''
|
||||
zfs create ${config._parent.name}/${config.name} \
|
||||
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") config.options)} -V ${config.size}
|
||||
udevadm trigger --subsystem-match=block; udevadm settle
|
||||
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") config.options)} \
|
||||
-V ${config.size}
|
||||
udevadm trigger --subsystem-match=block
|
||||
udevadm settle
|
||||
${lib.optionalString (config.content != null) config.content._create}
|
||||
'';
|
||||
};
|
||||
|
|
|
@ -83,7 +83,7 @@
|
|||
in
|
||||
{
|
||||
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}'
|
||||
${lib.concatMapStrings (x: x.dev or "") (lib.attrValues datasetMounts)}
|
||||
'';
|
||||
|
|
Loading…
Reference in a new issue