dream2nix/modules/flake-parts/checks.nix
DavHau db35339b1e test: add per module testing infra
So far, /examples was the only place with packages that are built in the CI pipeline.
This change allows us to add package build tests to individual modules at the location where the module is defined. This has several benefits:

- We are not forced to add unnecessary examples in order to maintain test coverage
- When modules get removed, their tests will be removed alongside
- It allows us to keep old modules around and assure they keep working without having to keep outdated examples in /examples
2023-11-17 07:27:54 +00:00

45 lines
1.1 KiB
Nix

{
self,
lib,
...
}: {
perSystem = {
self',
pkgs,
...
}: let
modules = self.modules.dream2nix;
modulesWithTests =
lib.filterAttrs
(_: module: lib.pathExists (module + /tests/packages))
modules;
getPackagePaths = moduleName: modulePath:
lib.concatMapAttrs
(packageDir: _: {
"module-${moduleName}-${packageDir}" = "${modulePath}/tests/packages/${packageDir}";
})
(builtins.readDir (modulePath + /tests/packages));
makePackage = testModulePath: let
evaled = lib.evalModules {
specialArgs = {
dream2nix.modules = self.modules;
packageSets.nixpkgs = pkgs;
};
modules = [
testModulePath
{
paths.projectRoot = testModulePath;
paths.package = testModulePath;
}
];
};
in
evaled.config.public;
packagesToBuild =
lib.concatMapAttrs getPackagePaths modulesWithTests;
packagesBuilt = lib.mapAttrs (_: makePackage) packagesToBuild;
in {
checks = self'.packages // packagesBuilt;
};
}