@@ -560,7 +560,7 @@ final: prev: {
561 ) (builtins.removeAttrs rawProject.hsPkgs
561 ) (builtins.removeAttrs rawProject.hsPkgs
562 # These are functions not packages
562 # These are functions not packages
563− [ "shellFor" "makeConfigFiles" "ghcWithHoogle" "ghcWithPackages" ]);
563+ [ "shellFor" "makeConfigFiles" "ghcWithHoogle" "ghcWithPackages" "buildPackages" ]);
565 projectCoverageReport = haskellLib.projectCoverageReport project (map (pkg: pkg.coverageReport) (final.lib.attrValues (haskellLib.selectProjectPackages hsPkgs)));
565 projectCoverageReport = haskellLib.projectCoverageReport project (map (pkg: pkg.coverageReport) (final.lib.attrValues (haskellLib.selectProjectPackages hsPkgs)));
@@ -568,6 +568,59 @@ final: prev: {
568 rawProject.projectFunction pkgs.haskell-nix rawProject.projectArgs
568 rawProject.projectFunction pkgs.haskell-nix rawProject.projectArgs
569 ) final.pkgsCross) // { recurseForDerivations = false; };
569 ) final.pkgsCross) // { recurseForDerivations = false; };
571+ # Helper function that can be used to make a Nix Flake out of a project
572+ # by including a flake.nix. See docs/tutorials/getting-started-flakes.md
573+ # for an example flake.nix file.
574+ # This flake function maps the build outputs to the flake `packages`,
575+ # `checks` and `apps` output attributes.
577+ packages ? haskellLib.selectProjectPackages
579+ let packageNames = builtins.attrNames (packages project.hsPkgs);
582+ # `nix build .#pkg-name:lib:pkg-name`
583+ # `nix build .#pkg-name:lib:sublib-name`
584+ # `nix build .#pkg-name:exe:exe-name`
585+ # `nix build .#pkg-name:test:test-name`
586+ packages = builtins.listToAttrs (
587+ final.lib.concatMap (packageName:
588+ let package = project.hsPkgs.${packageName};
589+ in final.lib.optional (package.components ? library)
590+ { name = "${packageName}:lib:${packageName}"; value = package.components.library; }
591+ ++ final.lib.mapAttrsToList (n: v:
592+ { name = "${packageName}:lib:${n}"; value = v; })
593+ (package.components.sublibs)
594+ ++ final.lib.mapAttrsToList (n: v:
595+ { name = "${packageName}:exe:${n}"; value = v; })
596+ (package.components.exes)
597+ ++ final.lib.mapAttrsToList (n: v:
598+ { name = "${packageName}:test:${n}"; value = v; })
599+ (package.components.tests)
602+ # `nix check .#pkg-name:test:test-name`
603+ checks = builtins.listToAttrs (
604+ final.lib.concatMap (packageName:
605+ let package = project.hsPkgs.${packageName};
606+ in final.lib.mapAttrsToList (n: v:
607+ { name = "${packageName}:test:${n}"; value = v; })
608+ (final.lib.filterAttrs (_: v: final.lib.isDerivation v) (package.checks))
611+ # `nix run .#pkg-name:exe:exe-name`
612+ # `nix run .#pkg-name:test:test-name`
613+ apps = builtins.listToAttrs (
614+ final.lib.concatMap (packageName:
615+ let package = project.hsPkgs.${packageName};
616+ in final.lib.mapAttrsToList (n: v:
617+ { name = "${packageName}:exe:${n}"; value = { type = "app"; program = v.exePath; }; })
618+ (package.components.exes)
619+ ++ final.lib.mapAttrsToList (n: v:
620+ { name = "${packageName}:test:${n}"; value = { type = "app"; program = v.exePath; }; })
621+ (package.components.tests)
571 inherit (rawProject.hsPkgs) makeConfigFiles ghcWithHoogle ghcWithPackages shellFor;
624 inherit (rawProject.hsPkgs) makeConfigFiles ghcWithHoogle ghcWithPackages shellFor;