Skip to content

Commit

Permalink
Merge pull request #28 from epics-extensions/checks-imports
Browse files Browse the repository at this point in the history
Checks imports
  • Loading branch information
minijackson committed Dec 1, 2023
2 parents 690a76c + 8945e8a commit 705292a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 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);
}
2 changes: 1 addition & 1 deletion templates/top/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down

0 comments on commit 705292a

Please sign in to comment.