Skip to content

Commit

Permalink
ioc/checks: rename files -> imports, allow raw configuration
Browse files Browse the repository at this point in the history
this simplifies parametrized tests
this is now possible:

    checks.imports = [
      (import ./checks/common.nix "epics-base3")
      (import ./checks/common.nix "epics-base7")
    ];
  • Loading branch information
minijackson committed Oct 6, 2023
1 parent e89c3e9 commit cdd169f
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions ioc/modules/checks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 =
Expand All @@ -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);
}

0 comments on commit cdd169f

Please sign in to comment.