on iko/ghcjs-patch-master help sign in
Add haskellNixRoots and withInputs to help caching (#271)

Now that haskell.nix relies on IFD internally it is helpful to have the nativeBuildInputs of the IFDs built and cached.

commit1a28ea9ca408e0c71dade383e6877ab79091308c authorHamish Mackenzie <Hamish.Mackenzie@iohk.io> dateMon 28 Oct 2019, 17:28 (7 years ago) parentb7a9e6a
3 files changed+35−3
build.nix+1−1 overlays/ghc-packages.nix+4−2 overlays/haskell.nix+30
build.nix+1−1
@@ -27,7 +27,7 @@ let
2727 haskell = pkgs.haskell-nix;
2828
2929in {
30− inherit (haskell) nix-tools source-pins;
30+ inherit (haskell) haskellNixRoots;
3131 tests = import ./test/default.nix { inherit nixpkgs nixpkgsArgs; };
3232
3333 # Scripts for keeping Hackage and Stackage up to date, and CI tasks.
overlays/ghc-packages.nix+4−2
@@ -81,10 +81,12 @@ in rec {
8181 '';
8282 }) self.buildPackages.haskell.compiler;
8383
84− ghc-extra-packages = builtins.mapAttrs (name: proj: self.haskell-nix.cabalProject {
84+ ghc-extra-projects = builtins.mapAttrs (name: proj: self.haskell-nix.cabalProject' {
8585 name = "ghc-extra-packages";
8686 src = proj;
8787 ghc = self.buildPackages.haskell.compiler.${name};
8888 })
8989 ghc-extra-pkgs-cabal-projects;
90−}
90+
91+ ghc-extra-packages = builtins.mapAttrs (_: proj: proj.hsPkgs) ghc-extra-projects;
92+}
overlays/haskell.nix+30
@@ -297,6 +297,9 @@ self: super: {
297297 '';
298298 in cabalProject (builtins.removeAttrs args [ "version" ] // { inherit src; });
299299
300+ # This function is like `cabalProject` but it makes the plan-nix available
301+ # separately from the hsPkgs. The advantage is that the you can get the
302+ # plan-nix without building the project.
300303 cabalProject' =
301304 { name ? null
302305 , ... }@args:
@@ -328,5 +331,32 @@ self: super: {
328331 ++ self.lib.optional (args ? cache) (mkCacheModule args.cache);
329332 };
330333 in pkg-set.config.hsPkgs;
334+
335+ # The functions that return a plan-nix often have a lot of dependencies
336+ # that could be GCed and also will not make it into hydra cache.
337+ # Use this `withInputs` function to make sure your tests include
338+ # the dependencies needed explicitly. For example, if you have:
339+ # project = cabalProject' {...};
340+ # In your tests module add something that is effectively
341+ # testProjectPlan = withInputs project.plan-nix;
342+ withInputs = derivation: builtins.mapAttrs (_: self.recurseIntoAttrs) {
343+ inherit derivation;
344+ inputs = builtins.listToAttrs (
345+ builtins.concatMap (i: if i == null then [] else [
346+ { name = builtins.replaceStrings ["."] ["_"] i.name; value = i; }
347+ ]) derivation.nativeBuildInputs);
348+ };
349+
350+ # Add this to your tests to make all the dependencies of haskell.nix
351+ # are tested and cached.
352+ haskellNixRoots = self.recurseIntoAttrs (builtins.mapAttrs (_: self.recurseIntoAttrs) {
353+ inherit (self.haskell-nix) nix-tools source-pins;
354+ bootstap-nix-tools = self.bootstrap.haskell.packages.nix-tools;
355+ alex-plan-nix = withInputs self.bootstrap.haskell.packages.alex-project.plan-nix;
356+ happy-plan-nix = withInputs self.bootstrap.haskell.packages.happy-project.plan-nix;
357+ hscolour-plan-nix = withInputs self.bootstrap.haskell.packages.hscolour-project.plan-nix;
358+ ghc-extra-projects = builtins.mapAttrs (_: proj: self.recurseIntoAttrs (withInputs proj.plan-nix))
359+ (self.lib.filterAttrs (n: _: n != "ghc844" && n != "ghc861" && n != "ghc862") self.ghc-extra-projects);
360+ });
331361 };
332362}