@@ -543,6 +543,9 @@ final: prev: {
543543 final.lib.fix (project':
544544 let project = project' // { recurseForDerivations = false; };
545545 in rawProject // rec {
546+ # It is often handy to be able to get nix pkgs from the project.
547+ pkgs = final;
548+ # Haskell packages
546549 hsPkgs = final.lib.mapAttrs (packageName: package':
547550 if package' == null
548551 then null
@@ -648,6 +651,9 @@ final: prev: {
648651 inputsFrom = args'.inputsFrom or [] ++ crossShells;
649652 });
650653
654+ # Default shell
655+ shell = shellFor rawProject.args.shell;
656+
651657 # Like `.hsPkgs.${packageName}` but when compined with `getComponent` any
652658 # cabal configure errors are defered until the components derivation builds.
653659 getPackage = packageName:
@@ -697,51 +703,64 @@ final: prev: {
697703 # `checks` and `apps` output attributes.
698704 flake = {
699705 packages ? haskellLib.selectProjectPackages
706+ , crossPlatforms ? p: []
700707 }:
701− let packageNames = builtins.attrNames (packages project.hsPkgs);
708+ let packageNames = project: builtins.attrNames (packages project.hsPkgs);
709+ packagesForProject = prefix: project:
710+ final.lib.concatMap (packageName:
711+ let package = project.hsPkgs.${packageName};
712+ in final.lib.optional (package.components ? library)
713+ { name = "${prefix}${packageName}:lib:${packageName}"; value = package.components.library; }
714+ ++ final.lib.mapAttrsToList (n: v:
715+ { name = "${prefix}${packageName}:lib:${n}"; value = v; })
716+ (package.components.sublibs)
717+ ++ final.lib.mapAttrsToList (n: v:
718+ { name = "${prefix}${packageName}:exe:${n}"; value = v; })
719+ (package.components.exes)
720+ ++ final.lib.mapAttrsToList (n: v:
721+ { name = "${prefix}${packageName}:test:${n}"; value = v; })
722+ (package.components.tests)
723+ ) (packageNames project);
724+ checksForProject = prefix: project:
725+ final.lib.concatMap (packageName:
726+ let package = project.hsPkgs.${packageName};
727+ in final.lib.mapAttrsToList (n: v:
728+ { name = "${packageName}:test:${n}"; value = v; })
729+ (final.lib.filterAttrs (_: v: final.lib.isDerivation v) (package.checks))
730+ ) (packageNames project);
731+ appsForProject = prefix: project:
732+ final.lib.concatMap (packageName:
733+ let package = project.hsPkgs.${packageName};
734+ in final.lib.mapAttrsToList (n: v:
735+ { name = "${packageName}:exe:${n}"; value = { type = "app"; program = v.exePath; }; })
736+ (package.components.exes)
737+ ++ final.lib.mapAttrsToList (n: v:
738+ { name = "${packageName}:test:${n}"; value = { type = "app"; program = v.exePath; }; })
739+ (package.components.tests)
740+ ) (packageNames project);
741+ attrsForAllProjects = f: builtins.listToAttrs (
742+ f "" project
743+ ++ final.lib.concatMap (project:
744+ f (project.pkgs.stdenv.hostPlatform.config + ":") project)
745+ (crossPlatforms project.projectCross)
746+ );
702747 in {
703748 # Used by:
704749 # `nix build .#pkg-name:lib:pkg-name`
705750 # `nix build .#pkg-name:lib:sublib-name`
706751 # `nix build .#pkg-name:exe:exe-name`
707752 # `nix build .#pkg-name:test:test-name`
708− packages = builtins.listToAttrs (
709− final.lib.concatMap (packageName:
710− let package = project.hsPkgs.${packageName};
711− in final.lib.optional (package.components ? library)
712− { name = "${packageName}:lib:${packageName}"; value = package.components.library; }
713− ++ final.lib.mapAttrsToList (n: v:
714− { name = "${packageName}:lib:${n}"; value = v; })
715− (package.components.sublibs)
716− ++ final.lib.mapAttrsToList (n: v:
717− { name = "${packageName}:exe:${n}"; value = v; })
718− (package.components.exes)
719− ++ final.lib.mapAttrsToList (n: v:
720− { name = "${packageName}:test:${n}"; value = v; })
721− (package.components.tests)
722− ) packageNames);
753+ packages = attrsForAllProjects packagesForProject;
723754 # Used by:
724755 # `nix check .#pkg-name:test:test-name`
725− checks = builtins.listToAttrs (
726− final.lib.concatMap (packageName:
727− let package = project.hsPkgs.${packageName};
728− in final.lib.mapAttrsToList (n: v:
729− { name = "${packageName}:test:${n}"; value = v; })
730− (final.lib.filterAttrs (_: v: final.lib.isDerivation v) (package.checks))
731− ) packageNames);
756+ checks = attrsForAllProjects checksForProject;
732757 # Used by:
733758 # `nix run .#pkg-name:exe:exe-name`
734759 # `nix run .#pkg-name:test:test-name`
735− apps = builtins.listToAttrs (
736− final.lib.concatMap (packageName:
737− let package = project.hsPkgs.${packageName};
738− in final.lib.mapAttrsToList (n: v:
739− { name = "${packageName}:exe:${n}"; value = { type = "app"; program = v.exePath; }; })
740− (package.components.exes)
741− ++ final.lib.mapAttrsToList (n: v:
742− { name = "${packageName}:test:${n}"; value = { type = "app"; program = v.exePath; }; })
743− (package.components.tests)
744− ) packageNames);
760+ apps = attrsForAllProjects appsForProject;
761+ # Used by:
762+ # `nix develop`
763+ devShell = project.shell;
745764 };
746765 inherit (rawProject.hsPkgs) makeConfigFiles ghcWithHoogle ghcWithPackages;
747766 });