fix inconsistent indentation with nixpkgs-fmt

This commit is contained in:
Jörg Thalheim 2022-08-26 08:41:58 +02:00
parent 1ac0e76b15
commit 69f1337980
8 changed files with 138 additions and 122 deletions

View file

@ -4,7 +4,8 @@ with builtins;
let let
helper.find-device = device: let helper.find-device = device:
let
environment = helper.device-id device; environment = helper.device-id device;
in in
# DEVICE points already to /dev/disk, so we don't handle it via /dev/disk/by-path # DEVICE points already to /dev/disk, so we don't handle it via /dev/disk/by-path
@ -87,10 +88,12 @@ let
${q.device} ${q.device}
''; '';
create.devices = q: x: let create.devices = q: x:
let
raid-devices = lib.filterAttrs (_: dev: dev.type == "mdadm" || dev.type == "zpool" || dev.type == "lvm_vg") x.content; raid-devices = lib.filterAttrs (_: dev: dev.type == "mdadm" || dev.type == "zpool" || dev.type == "lvm_vg") x.content;
other-devices = lib.filterAttrs (_: dev: dev.type != "mdadm" && dev.type != "zpool" && dev.type != "lvm_vg") x.content; other-devices = lib.filterAttrs (_: dev: dev.type != "mdadm" && dev.type != "zpool" && dev.type != "lvm_vg") x.content;
in '' in
''
${concatStrings (mapAttrsToList (name: create-f { device = "/dev/${name}"; }) other-devices)} ${concatStrings (mapAttrsToList (name: create-f { device = "/dev/${name}"; }) other-devices)}
${concatStrings (mapAttrsToList (name: create-f { device = "/dev/${name}"; name = name; }) raid-devices)} ${concatStrings (mapAttrsToList (name: create-f { device = "/dev/${name}"; name = name; }) raid-devices)}
''; '';
@ -134,9 +137,11 @@ let
create.noop = q: x: ""; create.noop = q: x: "";
create.partition = q: x: let create.partition = q: x:
let
env = helper.device-id q.device; env = helper.device-id q.device;
in '' in
''
parted -s "''${${env}}" mkpart ${x.part-type} ${x.fs-type or ""} ${x.start} ${x.end} parted -s "''${${env}}" mkpart ${x.part-type} ${x.fs-type or ""} ${x.start} ${x.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
@ -194,11 +199,13 @@ let
mount.btrfs = mount.filesystem; mount.btrfs = mount.filesystem;
mount.devices = q: x: let mount.devices = q: x:
let
z = foldl' recursiveUpdate { } (mapAttrsToList (name: mount-f { device = "/dev/${name}"; inherit name; }) x.content); z = foldl' recursiveUpdate { } (mapAttrsToList (name: mount-f { device = "/dev/${name}"; inherit name; }) x.content);
# attrValues returns values sorted by name. This is important, because it # attrValues returns values sorted by name. This is important, because it
# ensures that "/" is processed before "/foo" etc. # ensures that "/" is processed before "/foo" etc.
in '' in
''
${optionalString (hasAttr "table" z) (concatStringsSep "\n" (attrValues z.table))} ${optionalString (hasAttr "table" z) (concatStringsSep "\n" (attrValues z.table))}
${optionalString (hasAttr "luks" z) (concatStringsSep "\n" (attrValues z.luks))} ${optionalString (hasAttr "luks" z) (concatStringsSep "\n" (attrValues z.luks))}
${optionalString (hasAttr "lvm" z) (concatStringsSep "\n" (attrValues z.lvm))} ${optionalString (hasAttr "lvm" z) (concatStringsSep "\n" (attrValues z.lvm))}
@ -210,9 +217,11 @@ let
mount.luks = q: x: ( mount.luks = q: x: (
recursiveUpdate recursiveUpdate
(mount-f { device = "/dev/mapper/${x.name}"; } x.content) (mount-f { device = "/dev/mapper/${x.name}"; } x.content)
{luks.${q.device} = '' {
luks.${q.device} = ''
cryptsetup status ${x.name} >/dev/null 2>/dev/null || cryptsetup luksOpen ${q.device} ${x.name} ${if builtins.hasAttr "keyfile" x then "--key-file " + x.keyfile else ""} cryptsetup status ${x.name} >/dev/null 2>/dev/null || cryptsetup luksOpen ${q.device} ${x.name} ${if builtins.hasAttr "keyfile" x then "--key-file " + x.keyfile else ""}
'';} '';
}
); );
mount.lvm_lv = q: x: mount.lvm_lv = q: x:
@ -221,9 +230,11 @@ let
mount.lvm_vg = q: x: ( mount.lvm_vg = q: x: (
recursiveUpdate recursiveUpdate
(foldl' recursiveUpdate { } (mapAttrsToList (name: mount-f { inherit name; vgname = q.name; }) x.lvs)) (foldl' recursiveUpdate { } (mapAttrsToList (name: mount-f { inherit name; vgname = q.name; }) x.lvs))
{lvm.${q.device} = '' {
lvm.${q.device} = ''
vgchange -a y vgchange -a y
'';} '';
}
); );
mount.lvm_pv = mount.noop; mount.lvm_pv = mount.noop;
@ -248,9 +259,11 @@ let
mount.zpool = q: x: ( mount.zpool = q: x: (
recursiveUpdate recursiveUpdate
(foldl' recursiveUpdate { } (map (mount-f (q // { pool = q.name; })) x.datasets)) (foldl' recursiveUpdate { } (map (mount-f (q // { pool = q.name; })) x.datasets))
{zpool.${q.device} = '' {
zpool.${q.device} = ''
zpool list '${q.name}' >/dev/null 2>/dev/null || zpool import '${q.name}' zpool list '${q.name}' >/dev/null 2>/dev/null || zpool import '${q.name}'
'';} '';
}
); );
mount.zfs_filesystem = q: x: { mount.zfs_filesystem = q: x: {
@ -267,7 +280,8 @@ let
mount.zfs_volume = q: x: mount.zfs_volume = q: x:
mount-f { device = "/dev/zvol/${q.pool}/${x.name}"; } x.content; mount-f { device = "/dev/zvol/${q.pool}/${x.name}"; } x.content;
in { in
{
config = config-f { }; config = config-f { };
create = cfg: '' create = cfg: ''
set -efux set -efux

View file

@ -12,4 +12,5 @@ let
); );
allTests = lib.genAttrs (allTestFilenames) (test: import (./. + "/${test}.nix") { inherit makeDiskoTest; }); allTests = lib.genAttrs (allTestFilenames) (test: import (./. + "/${test}.nix") { inherit makeDiskoTest; });
in allTests in
allTests

View file

@ -3,10 +3,10 @@
, ... , ...
}: }:
{ {
makeDiskoTest = { makeDiskoTest =
disko-config, { disko-config
extraTestScript, , extraTestScript
extraConfig ? {} , extraConfig ? { }
}: }:
let let
lib = pkgs.lib; lib = pkgs.lib;
@ -18,7 +18,8 @@
tsp-create = pkgs.writeScript "create" ((pkgs.callPackage ../. { }).create disko-config); tsp-create = pkgs.writeScript "create" ((pkgs.callPackage ../. { }).create disko-config);
tsp-mount = pkgs.writeScript "mount" ((pkgs.callPackage ../. { }).mount disko-config); tsp-mount = pkgs.writeScript "mount" ((pkgs.callPackage ../. { }).mount disko-config);
num-disks = builtins.length (builtins.filter (x: builtins.match "vd." x == [ ]) (lib.attrNames disko-config.content)); num-disks = builtins.length (builtins.filter (x: builtins.match "vd." x == [ ]) (lib.attrNames disko-config.content));
in makeTest' { in
makeTest' {
name = "disko"; name = "disko";
nodes.machine = nodes.machine =