on iko/ghcjs-patch-master help sign in
Add project and package attrs to components (#657)

This is handy if you want to access `project.hsPkgs.shellFor` or `project.plan-nix` (will help with #653).

commit26b8c1c75ffebc2cdc410ded53d3fc4f7679c767 authorHamish Mackenzie <Hamish.Mackenzie@iohk.io> dateMon 8 Jun 2020, 12:45 (6 years ago) parent4bb7893
1 file changed+26−2
overlays/haskell.nix+26−2
overlays/haskell.nix+26−2
@@ -470,7 +470,31 @@ final: prev: {
470470 { compiler.nix-name = args.compiler-nix-name; };
471471 extra-hackages = args.extra-hackages or [];
472472 };
473− in { inherit (pkg-set.config) hsPkgs; inherit pkg-set; plan-nix = plan.nix; };
473+ in addProjectAndPackageAttrs { inherit (pkg-set.config) hsPkgs; inherit pkg-set; plan-nix = plan.nix; };
474+
475+ # Take `hsPkgs` from the `rawProject` and update all the packages and
476+ # components so they have a `.project` attribute and as well as
477+ # a `.package` attribute on the components.
478+ addProjectAndPackageAttrs = rawProject:
479+ final.lib.fix (project: rawProject // {
480+ hsPkgs = (final.lib.mapAttrs (n: package:
481+ if package == null
482+ then null
483+ else
484+ package // {
485+ components = final.lib.mapAttrs (n: v:
486+ if n == "library" || n == "all"
487+ then v // { inherit project package; }
488+ else final.lib.mapAttrs (_: c: c // { inherit project package; }) v
489+ ) package.components;
490+ inherit project;
491+ }
492+ ) rawProject.hsPkgs
493+ // {
494+ # These are functions not packages
495+ inherit (rawProject.hsPkgs) shellFor ghcWithHoogle ghcWithPackages;
496+ });
497+ });
474498
475499 cabalProject = args: let p = cabalProject' args;
476500 in p.hsPkgs // {
@@ -495,7 +519,7 @@ final: prev: {
495519 ++ (args.modules or [])
496520 ++ final.lib.optional (args ? ghc) { ghc.package = args.ghc; };
497521 };
498− in { inherit (pkg-set.config) hsPkgs; inherit pkg-set; stack-nix = stack.nix; };
522+ in addProjectAndPackageAttrs { inherit (pkg-set.config) hsPkgs; inherit pkg-set; stack-nix = stack.nix; };
499523
500524 stackProject = args: let p = stackProject' args;
501525 in p.hsPkgs // {