From 1237ac36db1a457ae561134d191d2924a9ce5ffc Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 25 Aug 2022 13:13:20 +0200 Subject: fix mdadm mounting, move test to mdadm test --- default.nix | 5 +++-- example/mdadm.nix | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ example/raid.nix | 60 ------------------------------------------------------- tests/mdadm.nix | 39 ++++++++++++++++++++++++++++++++++++ tests/test.nix | 38 ----------------------------------- 5 files changed, 101 insertions(+), 100 deletions(-) create mode 100644 example/mdadm.nix delete mode 100644 example/raid.nix create mode 100644 tests/mdadm.nix delete mode 100644 tests/test.nix diff --git a/default.nix b/default.nix index d20b67e..567324c 100644 --- a/default.nix +++ b/default.nix @@ -137,7 +137,7 @@ let }; mount.devices = q: x: let - z = foldl' recursiveUpdate {} (mapAttrsToList (name: mount-f { device = "/dev/${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 # ensures that "/" is processed before "/foo" etc. in '' @@ -168,8 +168,9 @@ let mount.noop = q: x: {}; + mount.mdadm = q: x: + mount-f { device = "/dev/md/${q.name}"; } x.content; # TODO maybe we need to do something here? - mount.mdadm = mount.noop; mount.mdraid = mount.noop; mount.partition = q: x: diff --git a/example/mdadm.nix b/example/mdadm.nix new file mode 100644 index 0000000..cb0ad91 --- /dev/null +++ b/example/mdadm.nix @@ -0,0 +1,59 @@ +# usage: nix-instantiate --eval --json --strict example/config.nix | jq . +{ + type = "devices"; + content = { + vdb = { + type = "table"; + format = "gpt"; + partitions = [ + { + type = "partition"; + part-type = "primary"; + start = "1MiB"; + end = "100%"; + content = { + type = "mdraid"; + name = "raid1"; + }; + } + ]; + }; + vdc = { + type = "table"; + format = "gpt"; + partitions = [ + { + type = "partition"; + part-type = "primary"; + start = "1MiB"; + end = "100%"; + content = { + type = "mdraid"; + name = "raid1"; + }; + } + ]; + }; + raid1 = { + type = "mdadm"; + level = 1; + content = { + type = "table"; + format = "gpt"; + partitions = [ + { + type = "partition"; + part-type = "primary"; + start = "1MiB"; + end = "100%"; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/raid"; + }; + } + ]; + }; + }; + }; +} diff --git a/example/raid.nix b/example/raid.nix deleted file mode 100644 index 490ea01..0000000 --- a/example/raid.nix +++ /dev/null @@ -1,60 +0,0 @@ -# usage: nix-instantiate --eval --json --strict example/config.nix | jq . -{ - type = "devices"; - content = { - vdb = { - type = "table"; - format = "gpt"; - partitions = [ - { - type = "partition"; - part-type = "primary"; - start = "1MiB"; - end = "100%"; - content = { - type = "mdraid"; - name = "raid1"; - }; - } - ]; - }; - vdc = { - type = "table"; - format = "gpt"; - partitions = [ - { - type = "partition"; - part-type = "primary"; - start = "1MiB"; - end = "100%"; - content = { - type = "mdraid"; - name = "raid1"; - }; - } - ]; - }; - raid1 = { - type = "mdadm"; - level = 1; - content = { - type = "table"; - format = "gpt"; - partitions = [ - { - type = "partition"; - part-type = "primary"; - start = "1MiB"; - end = "100%"; - content = { - type = "filesystem"; - format = "ext4"; - mountpoint = "/raid"; - }; - } - ]; - - }; - }; - }; -} diff --git a/tests/mdadm.nix b/tests/mdadm.nix new file mode 100644 index 0000000..37465e4 --- /dev/null +++ b/tests/mdadm.nix @@ -0,0 +1,39 @@ +{ makeTest ? import +, pkgs ? (import {}) +}: +let + makeTest' = args: + makeTest args { + inherit pkgs; + inherit (pkgs) system; + }; + disko-config = import ../example/mdadm.nix; + tsp-create = pkgs.writeScript "create" ((pkgs.callPackage ../. {}).create disko-config); + tsp-mount = pkgs.writeScript "mount" ((pkgs.callPackage ../. {}).mount disko-config); +in makeTest' { + name = "disko"; + + nodes.machine = + { config, pkgs, modulesPath, ... }: + + { + imports = [ + (modulesPath + "/profiles/installation-device.nix") + (modulesPath + "/profiles/base.nix") + ]; + + # speed-up eval + documentation.enable = false; + + virtualisation.emptyDiskImages = [ 512 512 ]; + }; + + testScript = '' + machine.succeed("echo 'secret' > /tmp/secret.key"); + machine.succeed("${tsp-create}"); + machine.succeed("${tsp-mount}"); + machine.succeed("${tsp-mount}"); # verify that the command is idempotent + machine.succeed("test -b /dev/md/raid1"); + machine.succeed("grep -qs '/mnt/raid' /proc/mounts"); + ''; +} diff --git a/tests/test.nix b/tests/test.nix deleted file mode 100644 index 1384590..0000000 --- a/tests/test.nix +++ /dev/null @@ -1,38 +0,0 @@ -{ makeTest ? import -, pkgs ? (import {}) -}: -let - makeTest' = args: - makeTest args { - inherit pkgs; - inherit (pkgs) system; - }; - disko-config = import ../example/raid.nix; - tsp-create = pkgs.writeScript "create" ((pkgs.callPackage ../. {}).create disko-config); - tsp-mount = pkgs.writeScript "mount" ((pkgs.callPackage ../. {}).mount disko-config); -in makeTest' { - name = "disko"; - - nodes.machine = - { config, pkgs, modulesPath, ... }: - - { - imports = [ - (modulesPath + "/profiles/installation-device.nix") - (modulesPath + "/profiles/base.nix") - ]; - - # speed-up eval - documentation.enable = false; - - virtualisation.emptyDiskImages = [ 512 512 ]; - }; - - testScript = '' - machine.succeed("echo 'secret' > /tmp/secret.key"); - machine.succeed("${tsp-create}"); - machine.succeed("${tsp-mount}"); - machine.succeed("${tsp-mount}"); # verify that the command is idempotent - machine.succeed("test -b /dev/md/raid1"); - ''; -} -- cgit v1.2.3