From cdd169f916c63395a8094c3d807dd7ca3a68f0e4 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Fri, 6 Oct 2023 16:04:50 +0200 Subject: [PATCH 1/2] ioc/checks: rename files -> imports, allow raw configuration this simplifies parametrized tests this is now possible: checks.imports = [ (import ./checks/common.nix "epics-base3") (import ./checks/common.nix "epics-base7") ]; --- ioc/modules/checks.nix | 43 ++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/ioc/modules/checks.nix b/ioc/modules/checks.nix index a9f7ccbb..d3e96373 100644 --- a/ioc/modules/checks.nix +++ b/ioc/modules/checks.nix @@ -9,17 +9,23 @@ with lib; let cfg = config.epnix.checks; in { + imports = [ + (mkRenamedOptionModule ["epnix" "checks" "files"] ["epnix" "checks" "imports"]) + ]; + options.epnix.checks = { - files = mkOption { + imports = mkOption { description = '' A list of `.nix` files containing integration tests. + Alternatively, a raw configuration can be specified. + Please refer to the documentation book guide "Writing integration tests" for instructions on how to write these `.nix` files. ''; - type = with types; listOf path; + type = with types; listOf (oneOf [path attrs (functionTo attrs)]); default = []; - example = ["./checks/simple.nix"]; + example = lib.literalExpression "[./checks/simple.nix]"; }; derivations = mkOption { @@ -34,15 +40,8 @@ in { }; config.epnix.checks.derivations = let - checkName = path: - pipe path [ - baseNameOf - (splitString ".") - head - ]; - - importCheck = path: - import path { + importCheck = check: let + params = { inherit pkgs epnix epnixConfig; build = @@ -55,9 +54,21 @@ in { '' config.epnix.outputs.build; }; + + # Do different things, + # depending on if the check is a file, an attrSet, or a function + switch = { + path = path: import path params; + set = set: set; + lambda = lambda: lambda params; + }; + + importedCheck = + switch."${builtins.typeOf check}" check; + + inherit (importedCheck.config) name; + in + nameValuePair name importedCheck; in - listToAttrs - (forEach - cfg.files - (file: nameValuePair (checkName file) (importCheck file))); + listToAttrs (map importCheck cfg.imports); } From 8945e8a42c2c535e65e6a1c20b06785c049dd824 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Fri, 6 Oct 2023 16:06:15 +0200 Subject: [PATCH 2/2] templates/top: use new checks.imports option --- templates/top/flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/top/flake.nix b/templates/top/flake.nix index c244447e..9ea2c6a2 100644 --- a/templates/top/flake.nix +++ b/templates/top/flake.nix @@ -43,7 +43,7 @@ # Add your integration tests: # --- - checks.files = [./checks/simple.nix]; + checks.imports = [./checks/simple.nix]; # Used when generating NixOS systemd services, for example for # deployment to production, or for the NixOS tests in checks/