Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checks imports #28

Merged
merged 2 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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