Skip to content

Commit 4b28d65

Browse files
Try #1743:
2 parents b302c7a + 71cb0b9 commit 4b28d65

File tree

2 files changed

+97
-86
lines changed

2 files changed

+97
-86
lines changed

lib/default.nix

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ in {
370370
value = flake.devShells.${n};
371371
}) (__attrNames flake.devShells));
372372
} // lib.optionalAttrs (flake ? hydraJobs) {
373-
hydraJobs.${lib.removeSuffix ":" prefix} = flake.hydraJobs;
373+
hydraJobs = prefixAttrs (prefix + sep) flake.hydraJobs;
374374
};
375375

376376
# Used by `combineFlakes` to combine flakes together
@@ -393,4 +393,97 @@ in {
393393
# one in the list will be used.
394394
combineFlakes = sep: prefixAndFlakes: builtins.foldl' addFlakes {}
395395
(lib.mapAttrsToList (prefix: flake: prefixFlake prefix sep flake) prefixAndFlakes);
396+
397+
mkFlake = project: packages: coverageProjectModule:
398+
let
399+
packageNames = project: builtins.attrNames (project.args.flake.packages project.hsPkgs);
400+
checkedProject = project.appendModule { checkMaterialization = true; };
401+
coverageProject = project.appendModule [
402+
coverageProjectModule
403+
{
404+
modules = [{
405+
packages = lib.genAttrs (packageNames project)
406+
(_: { doCoverage = lib.mkDefault true; });
407+
}];
408+
}
409+
];
410+
checks = builtins.listToAttrs (
411+
lib.concatMap (packageName:
412+
let package = project.hsPkgs.${packageName};
413+
in lib.mapAttrsToList (n: v:
414+
{ name = "${packageName}:test:${n}"; value = v; })
415+
(lib.filterAttrs (_: v: lib.isDerivation v) (package.checks))
416+
) (packageNames project));
417+
in {
418+
# Used by:
419+
# `nix build .#pkg-name:lib:pkg-name`
420+
# `nix build .#pkg-name:lib:sublib-name`
421+
# `nix build .#pkg-name:exe:exe-name`
422+
# `nix build .#pkg-name:test:test-name`
423+
packages = builtins.listToAttrs (
424+
lib.concatMap (packageName:
425+
let package = project.hsPkgs.${packageName};
426+
in lib.optional (package.components ? library)
427+
{ name = "${packageName}:lib:${packageName}"; value = package.components.library; }
428+
++ lib.mapAttrsToList (n: v:
429+
{ name = "${packageName}:lib:${n}"; value = v; })
430+
(package.components.sublibs)
431+
++ lib.mapAttrsToList (n: v:
432+
{ name = "${packageName}:exe:${n}"; value = v; })
433+
(package.components.exes)
434+
++ lib.mapAttrsToList (n: v:
435+
{ name = "${packageName}:test:${n}"; value = v; })
436+
(package.components.tests)
437+
++ lib.mapAttrsToList (n: v:
438+
{ name = "${packageName}:bench:${n}"; value = v; })
439+
(package.components.benchmarks)
440+
) (packageNames project));
441+
# Used by:
442+
# `nix flake check`
443+
inherit checks;
444+
# `nix run .#pkg-name:exe:exe-name`
445+
# `nix run .#pkg-name:test:test-name`
446+
apps = builtins.listToAttrs (
447+
lib.concatMap (packageName:
448+
let package = project.hsPkgs.${packageName};
449+
in lib.mapAttrsToList (n: v:
450+
{ name = "${packageName}:exe:${n}"; value = { type = "app"; program = v.exePath; }; })
451+
(package.components.exes)
452+
++ lib.mapAttrsToList (n: v:
453+
{ name = "${packageName}:test:${n}"; value = { type = "app"; program = v.exePath; }; })
454+
(package.components.tests)
455+
++ lib.mapAttrsToList (n: v:
456+
{ name = "${packageName}:benchmark:${n}"; value = { type = "app"; program = v.exePath; }; })
457+
(package.components.benchmarks)
458+
) (packageNames project));
459+
# Used by hydra and cicero:
460+
hydraJobs =
461+
prefixAttrs "checks:" checks
462+
463+
# Build the plan-nix and check it if materialized
464+
// lib.optionalAttrs (checkedProject ? plan-nix) {
465+
plan-nix = checkedProject.plan-nix;
466+
}
467+
468+
# Build the stack-nix and check it if materialized
469+
// lib.optionalAttrs (checkedProject ? stack-nix) {
470+
stack-nix = checkedProject.stack-nix;
471+
}
472+
473+
// {
474+
# Build tools and cache tools needed for the project
475+
inherit (project) roots;
476+
# Also build and cache any tools in the `devShell`
477+
devShell = project.shell;
478+
}
479+
480+
# Run HPC on the tests
481+
// builtins.listToAttrs (lib.concatMap (packageName: [{
482+
name = "coverage:" + packageName;
483+
value = coverageProject.hsPkgs.${packageName}.coverageReport;
484+
}]) (packageNames coverageProject))
485+
;
486+
devShells.default = project.shell;
487+
devShell = project.shell;
488+
};
396489
}

overlays/haskell.nix

Lines changed: 3 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -737,89 +737,6 @@ final: prev: {
737737
"Invalid package component name ${componentName}. Expected package:ctype:component (where ctype is one of lib, flib, exe, test, or bench)";
738738
(getPackage (builtins.elemAt m 0)).getComponent "${builtins.elemAt m 1}:${builtins.elemAt m 2}";
739739

740-
rawFlake =
741-
let
742-
packageNames = project: builtins.attrNames (project.args.flake.packages project.hsPkgs);
743-
checkedProject = project.appendModule { checkMaterialization = true; };
744-
in {
745-
# Used by:
746-
# `nix build .#pkg-name:lib:pkg-name`
747-
# `nix build .#pkg-name:lib:sublib-name`
748-
# `nix build .#pkg-name:exe:exe-name`
749-
# `nix build .#pkg-name:test:test-name`
750-
packages = builtins.listToAttrs (
751-
final.lib.concatMap (packageName:
752-
let package = project.hsPkgs.${packageName};
753-
in final.lib.optional (package.components ? library)
754-
{ name = "${packageName}:lib:${packageName}"; value = package.components.library; }
755-
++ final.lib.mapAttrsToList (n: v:
756-
{ name = "${packageName}:lib:${n}"; value = v; })
757-
(package.components.sublibs)
758-
++ final.lib.mapAttrsToList (n: v:
759-
{ name = "${packageName}:exe:${n}"; value = v; })
760-
(package.components.exes)
761-
++ final.lib.mapAttrsToList (n: v:
762-
{ name = "${packageName}:test:${n}"; value = v; })
763-
(package.components.tests)
764-
++ final.lib.mapAttrsToList (n: v:
765-
{ name = "${packageName}:bench:${n}"; value = v; })
766-
(package.components.benchmarks)
767-
) (packageNames project));
768-
# Used by:
769-
# `nix flake check`
770-
checks = builtins.listToAttrs (
771-
final.lib.concatMap (packageName:
772-
let package = project.hsPkgs.${packageName};
773-
in final.lib.mapAttrsToList (n: v:
774-
{ name = "${packageName}:test:${n}"; value = v; })
775-
(final.lib.filterAttrs (_: v: final.lib.isDerivation v) (package.checks))
776-
) (packageNames project));
777-
# `nix run .#pkg-name:exe:exe-name`
778-
# `nix run .#pkg-name:test:test-name`
779-
apps = builtins.listToAttrs (
780-
final.lib.concatMap (packageName:
781-
let package = project.hsPkgs.${packageName};
782-
in final.lib.mapAttrsToList (n: v:
783-
{ name = "${packageName}:exe:${n}"; value = { type = "app"; program = v.exePath; }; })
784-
(package.components.exes)
785-
++ final.lib.mapAttrsToList (n: v:
786-
{ name = "${packageName}:test:${n}"; value = { type = "app"; program = v.exePath; }; })
787-
(package.components.tests)
788-
++ final.lib.mapAttrsToList (n: v:
789-
{ name = "${packageName}:benchmark:${n}"; value = { type = "app"; program = v.exePath; }; })
790-
(package.components.benchmarks)
791-
) (packageNames project));
792-
# Used by hydra:
793-
hydraJobs = {
794-
checks = rawFlake.checks;
795-
} // final.lib.optionalAttrs (checkedProject ? plan-nix) {
796-
# Build the plan-nix and check it if materialized
797-
plan-nix = checkedProject.plan-nix;
798-
} // final.lib.optionalAttrs (checkedProject ? stack-nix) {
799-
# Build the stack-nix and check it if materialized
800-
stack-nix = checkedProject.stack-nix;
801-
} // {
802-
# Build tools and cache tools needed for the project
803-
roots = project.roots;
804-
coverage =
805-
let
806-
coverageProject = project.appendModule [
807-
project.args.flake.coverage
808-
{
809-
modules = [{
810-
packages = final.lib.genAttrs (packageNames project)
811-
(_: { doCoverage = final.lib.mkDefault true; });
812-
}];
813-
}
814-
];
815-
in builtins.listToAttrs (final.lib.concatMap (packageName: [{
816-
name = packageName;
817-
value = coverageProject.hsPkgs.${packageName}.coverageReport;
818-
}]) (packageNames coverageProject));
819-
};
820-
devShells.default = project.shell;
821-
devShell = project.shell;
822-
};
823740
# Helper function that can be used to make a Nix Flake out of a project
824741
# by including a flake.nix. See docs/tutorials/getting-started-flakes.md
825742
# for an example flake.nix file.
@@ -829,9 +746,10 @@ final: prev: {
829746
let
830747
combinePrefix = a: b: if a == "default" then b else "${a}:${b}";
831748
forAllCrossCompilers = prefix: project: (
832-
[{ ${prefix} = project.rawFlake; }]
749+
[{ ${prefix} = haskellLib.mkFlake project project.args.flake.packages project.args.flake.coverage; }]
833750
++ (map (project: {
834-
${combinePrefix prefix project.pkgs.stdenv.hostPlatform.config} = project.rawFlake;
751+
${combinePrefix prefix project.pkgs.stdenv.hostPlatform.config} =
752+
haskellLib.mkFlake project project.args.flake.packages project.args.flake.coverage;
835753
})
836754
(project.args.flake.crossPlatforms project.projectCross)
837755
));

0 commit comments

Comments
 (0)