2022-08-26 06:41:58 +00:00
|
|
|
{ pkgs ? (import <nixpkgs> { })
|
2022-08-25 21:12:49 +00:00
|
|
|
, makeTest ? import <nixpkgs/nixos/tests/make-test-python.nix>
|
|
|
|
, ...
|
|
|
|
}:
|
|
|
|
{
|
2022-08-26 06:41:58 +00:00
|
|
|
makeDiskoTest =
|
|
|
|
{ disko-config
|
|
|
|
, extraTestScript
|
|
|
|
, extraConfig ? { }
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
lib = pkgs.lib;
|
|
|
|
makeTest' = args:
|
|
|
|
makeTest args {
|
|
|
|
inherit pkgs;
|
|
|
|
inherit (pkgs) system;
|
|
|
|
};
|
|
|
|
tsp-create = pkgs.writeScript "create" ((pkgs.callPackage ../. { }).create disko-config);
|
|
|
|
tsp-mount = pkgs.writeScript "mount" ((pkgs.callPackage ../. { }).mount disko-config);
|
2022-08-29 09:45:19 +00:00
|
|
|
num-disks = builtins.length (lib.attrNames disko-config.disk);
|
2022-08-26 06:41:58 +00:00
|
|
|
in
|
|
|
|
makeTest' {
|
|
|
|
name = "disko";
|
2022-08-25 21:12:49 +00:00
|
|
|
|
2022-08-26 06:41:58 +00:00
|
|
|
nodes.machine =
|
|
|
|
{ config, pkgs, modulesPath, ... }:
|
2022-08-25 21:12:49 +00:00
|
|
|
|
2022-08-26 06:41:58 +00:00
|
|
|
{
|
|
|
|
imports = [
|
|
|
|
(modulesPath + "/profiles/installation-device.nix")
|
|
|
|
(modulesPath + "/profiles/base.nix")
|
|
|
|
];
|
2022-08-25 21:12:49 +00:00
|
|
|
|
2022-08-26 06:41:58 +00:00
|
|
|
# speed-up eval
|
|
|
|
documentation.enable = false;
|
2022-08-25 21:12:49 +00:00
|
|
|
|
2022-08-26 06:41:58 +00:00
|
|
|
virtualisation.emptyDiskImages = builtins.genList (_: 512) num-disks;
|
|
|
|
} // extraConfig;
|
2022-08-25 21:12:49 +00:00
|
|
|
|
2022-08-26 06:41:58 +00:00
|
|
|
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
|
|
|
|
${extraTestScript}
|
|
|
|
'';
|
|
|
|
};
|
2022-08-25 21:12:49 +00:00
|
|
|
}
|