dream2nix/modules/flake-parts/checks.nix-unit.nix

38 lines
1.1 KiB
Nix
Raw Normal View History

# evaluate packages from `/**/modules/drvs` and export them via `flake.packages`
{self, ...}: {
perSystem = {
pkgs,
inputs',
2023-09-20 23:03:03 +03:00
lib,
system,
...
2023-09-28 20:19:40 +03:00
}: let
modulesFlake = import "${self}/modules";
inputs = lib.mapAttrs (name: input: "${input.outPath}") modulesFlake.inputs;
inputsFile = builtins.toFile "inputs.json" (builtins.toJSON inputs);
in
2023-09-20 23:03:03 +03:00
lib.optionalAttrs (system == "x86_64-linux") {
# map all modules in /examples to a package output in the flake.
2023-09-28 20:19:40 +03:00
checks.nix-unit =
pkgs.runCommand "nix-unit-tests" {
nativeBuildInputs = [
pkgs.nix
];
} ''
export NIX_PATH=nixpkgs=${pkgs.path}
export HOME=$(realpath .)
for test in ${self}/tests/nix-unit/*; do
if [ -f "$test" ]; then
continue
fi
echo -e "Executing tests from file $test"
${inputs'.nix-unit.packages.nix-unit}/bin/nix-unit \
"$test" \
--eval-store $(realpath .) \
--arg inputs 'builtins.fromJSON (builtins.readFile ${inputsFile})'
done
touch $out
'';
2023-09-20 23:03:03 +03:00
};
}