on iko/ghcjs-patch-master help sign in
Merge PR #147
commit2a88f7ded3a8c9b7cf082748dcb76f1005acc059 authorRodney Lorrimar <rodney.lorrimar@iohk.io> dateWed 29 May 2019, 08:29 (7 years ago) parent7b4d68c2cbfbac
5 files changed+57−20
builder/default.nix+8−1 builder/make-config-files.nix+1−10 builder/shell-for.nix+29−9 lib/default.nix+12 test/tests.sh+7
builder/default.nix+8−1
@@ -20,6 +20,13 @@ let
2020 inherit ghc haskellLib nonReinstallablePkgs;
2121 };
2222
23+ hoogleLocal = let
24+ nixpkgsHoogleLocal = import (pkgs.path + /pkgs/development/haskell-modules/hoogle.nix);
25+ in { packages ? [], hoogle ? pkgs.haskellPackages.hoogle }:
26+ haskellLib.weakCallPackage pkgs nixpkgsHoogleLocal {
27+ inherit packages hoogle;
28+ };
29+
2330in {
2431 # Build a Haskell package from its config.
2532 # TODO: this pkgs is the adjusted pkgs, but pkgs.pkgs is unadjusted
@@ -29,7 +36,7 @@ in {
2936
3037 # Same as haskellPackages.shellFor in nixpkgs.
3138 shellFor = haskellLib.weakCallPackage pkgs ./shell-for.nix {
32− inherit hsPkgs ghcForComponent makeConfigFiles;
39+ inherit hsPkgs ghcForComponent makeConfigFiles hoogleLocal haskellLib;
3340 inherit (buildPackages) glibcLocales;
3441 };
3542}
builder/make-config-files.nix+1−10
@@ -6,15 +6,6 @@ let
66 echo "${field}: ${lib.concatStringsSep " " xs}" >> $out/cabal.config
77 '';
88
9− flatDepends = component:
10− let
11− makePairs = map (p: rec { key="${val}"; val=(p.components.library or p); });
12− closure = builtins.genericClosure {
13− startSet = makePairs component.depends;
14− operator = {val,...}: makePairs val.config.depends;
15− };
16− in map ({val,...}: val) closure;
17−
189 exactDep = pdbArg: p: ''
1910 if id=$(target-pkg ${pdbArg} field ${p} id --simple-output); then
2011 echo "--dependency=${p}=$id" >> $out/configure-flags
@@ -58,7 +49,7 @@ in { identifier, component, fullName, flags ? {} }:
5849
5950 ${lib.concatMapStringsSep "\n" (p: ''
6051 target-pkg --package-db ${p}/package.conf.d dump | target-pkg --force --package-db $out/package.conf.d register -
61− '') (flatDepends component)}
52+ '') (haskellLib.flatLibDepends component)}
6253
6354 # Note: we pass `clear` first to ensure that we never consult the implicit global package db.
6455 ${flagsAndConfig "package-db" ["clear" "$out/package.conf.d"]}
builder/shell-for.nix+29−9
@@ -1,4 +1,4 @@
1−{ lib, stdenv, glibcLocales, pkgconfig, ghcForComponent, makeConfigFiles, hsPkgs }:
1+{ lib, stdenv, glibcLocales, pkgconfig, ghcForComponent, makeConfigFiles, hsPkgs, hoogleLocal, haskellLib }:
22
33{ packages, withHoogle ? true, ... } @ args:
44
@@ -23,27 +23,47 @@ let
2323 nativeBuildInputs = lib.concatMap (p: p.components.all.executableToolDepends) selected;
2424
2525 # Set up a "dummy" component to use with ghcForComponent.
26+ component = {
27+ depends = packageInputs;
28+ libs = [];
29+ frameworks = [];
30+ doExactConfig = false;
31+ };
2632 configFiles = makeConfigFiles {
2733 fullName = args.name or name;
2834 identifier.name = name;
29− component = {
30− depends = packageInputs;
31− libs = [];
32− frameworks = [];
33− doExactConfig = false;
34− };
35+ inherit component;
3536 };
3637 ghcEnv = ghcForComponent {
3738 componentName = name;
3839 inherit configFiles;
3940 };
41+
42+ hoogleIndex = let
43+ # Get the doc package for a component, and add attributes that
44+ # hoogle.nix expects.
45+ docPackage = p: lib.getOutput "doc" p // {
46+ pname = p.identifier.name;
47+ haddockDir = lib.const p.haddockDir;
48+ };
49+ in hoogleLocal {
50+ packages = map docPackage (haskellLib.flatLibDepends component);
51+
52+ # Need to add hoogle to hsPkgs.
53+ # inherit (hsPkgs) hoogle;
54+ };
55+
4056 mkDrvArgs = builtins.removeAttrs args ["packages" "withHoogle"];
4157in
4258 stdenv.mkDerivation (mkDrvArgs // {
4359 name = mkDrvArgs.name or name;
4460
45− buildInputs = systemInputs ++ mkDrvArgs.buildInputs or [];
46− nativeBuildInputs = [ ghcEnv ] ++ nativeBuildInputs ++ mkDrvArgs.nativeBuildInputs or [];
61+ buildInputs = systemInputs
62+ ++ mkDrvArgs.buildInputs or []
63+ ++ lib.optional withHoogle hoogleIndex;
64+ nativeBuildInputs = [ ghcEnv ]
65+ ++ nativeBuildInputs
66+ ++ mkDrvArgs.nativeBuildInputs or [];
4767 phases = ["installPhase"];
4868 installPhase = "echo $nativeBuildInputs $buildInputs > $out";
4969 LANG = "en_US.UTF-8";
lib/default.nix+12
@@ -80,4 +80,16 @@ with haskellLib;
8080 let f' = if lib.isFunction f then f else import f;
8181 args' = (builtins.intersectAttrs (builtins.functionArgs f') scope) // args;
8282 in f' args';
83+
84+ # Collect all (transitive) Haskell library dependencies of a
85+ # component.
86+ ## flatLibDepends :: Component -> [Package]
87+ flatLibDepends = component:
88+ let
89+ makePairs = map (p: rec { key="${val}"; val=(p.components.library or p); });
90+ closure = builtins.genericClosure {
91+ startSet = makePairs component.depends;
92+ operator = {val,...}: makePairs val.config.depends;
93+ };
94+ in map ({val,...}: val) closure;
8395}
test/tests.sh+7
@@ -61,4 +61,11 @@ nix-shell $NIX_BUILD_ARGS \
6161 --run 'cd shell-for && cabal new-build all'
6262echo >& 2
6363
64+printf "*** Checking shellFor has a working hoogle index...\n" >& 2
65+nix-shell $NIX_BUILD_ARGS \
66+ --pure ./default.nix \
67+ -A shell-for.env \
68+ --run 'hoogle ConduitT | grep Data.Conduit'
69+echo >& 2
70+
6471printf "\n*** Finished successfully\n" >& 2