Skip to content

Build Hoogle index for development shell #147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion builder/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ let
inherit ghc haskellLib nonReinstallablePkgs;
};

hoogleLocal = let
nixpkgsHoogleLocal = import (pkgs.path + /pkgs/development/haskell-modules/hoogle.nix);
in { packages ? [], hoogle ? pkgs.haskellPackages.hoogle }:
haskellLib.weakCallPackage pkgs nixpkgsHoogleLocal {
inherit packages hoogle;
};

in {
# Build a Haskell package from its config.
# TODO: this pkgs is the adjusted pkgs, but pkgs.pkgs is unadjusted
Expand All @@ -29,7 +36,7 @@ in {

# Same as haskellPackages.shellFor in nixpkgs.
shellFor = haskellLib.weakCallPackage pkgs ./shell-for.nix {
inherit hsPkgs ghcForComponent makeConfigFiles;
inherit hsPkgs ghcForComponent makeConfigFiles hoogleLocal haskellLib;
inherit (buildPackages) glibcLocales;
};
}
11 changes: 1 addition & 10 deletions builder/make-config-files.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@ let
echo "${field}: ${lib.concatStringsSep " " xs}" >> $out/cabal.config
'';

flatDepends = component:
let
makePairs = map (p: rec { key="${val}"; val=(p.components.library or p); });
closure = builtins.genericClosure {
startSet = makePairs component.depends;
operator = {val,...}: makePairs val.config.depends;
};
in map ({val,...}: val) closure;

exactDep = pdbArg: p: ''
if id=$(target-pkg ${pdbArg} field ${p} id --simple-output); then
echo "--dependency=${p}=$id" >> $out/configure-flags
Expand Down Expand Up @@ -58,7 +49,7 @@ in { identifier, component, fullName, flags ? {} }:

${lib.concatMapStringsSep "\n" (p: ''
target-pkg --package-db ${p}/package.conf.d dump | target-pkg --force --package-db $out/package.conf.d register -
'') (flatDepends component)}
'') (haskellLib.flatLibDepends component)}

# Note: we pass `clear` first to ensure that we never consult the implicit global package db.
${flagsAndConfig "package-db" ["clear" "$out/package.conf.d"]}
Expand Down
38 changes: 29 additions & 9 deletions builder/shell-for.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ lib, stdenv, glibcLocales, pkgconfig, ghcForComponent, makeConfigFiles, hsPkgs }:
{ lib, stdenv, glibcLocales, pkgconfig, ghcForComponent, makeConfigFiles, hsPkgs, hoogleLocal, haskellLib }:

{ packages, withHoogle ? true, ... } @ args:

Expand All @@ -23,27 +23,47 @@ let
nativeBuildInputs = lib.concatMap (p: p.components.all.executableToolDepends) selected;

# Set up a "dummy" component to use with ghcForComponent.
component = {
depends = packageInputs;
libs = [];
frameworks = [];
doExactConfig = false;
};
configFiles = makeConfigFiles {
fullName = args.name or name;
identifier.name = name;
component = {
depends = packageInputs;
libs = [];
frameworks = [];
doExactConfig = false;
};
inherit component;
};
ghcEnv = ghcForComponent {
componentName = name;
inherit configFiles;
};

hoogleIndex = let
# Get the doc package for a component, and add attributes that
# hoogle.nix expects.
docPackage = p: lib.getOutput "doc" p // {
pname = p.identifier.name;
haddockDir = lib.const p.haddockDir;
};
in hoogleLocal {
packages = map docPackage (haskellLib.flatLibDepends component);

# Need to add hoogle to hsPkgs.
# inherit (hsPkgs) hoogle;
};

mkDrvArgs = builtins.removeAttrs args ["packages" "withHoogle"];
in
stdenv.mkDerivation (mkDrvArgs // {
name = mkDrvArgs.name or name;

buildInputs = systemInputs ++ mkDrvArgs.buildInputs or [];
nativeBuildInputs = [ ghcEnv ] ++ nativeBuildInputs ++ mkDrvArgs.nativeBuildInputs or [];
buildInputs = systemInputs
++ mkDrvArgs.buildInputs or []
++ lib.optional withHoogle hoogleIndex;
nativeBuildInputs = [ ghcEnv ]
++ nativeBuildInputs
++ mkDrvArgs.nativeBuildInputs or [];
phases = ["installPhase"];
installPhase = "echo $nativeBuildInputs $buildInputs > $out";
LANG = "en_US.UTF-8";
Expand Down
12 changes: 12 additions & 0 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,16 @@ with haskellLib;
let f' = if lib.isFunction f then f else import f;
args' = (builtins.intersectAttrs (builtins.functionArgs f') scope) // args;
in f' args';

# Collect all (transitive) Haskell library dependencies of a
# component.
## flatLibDepends :: Component -> [Package]
flatLibDepends = component:
let
makePairs = map (p: rec { key="${val}"; val=(p.components.library or p); });
closure = builtins.genericClosure {
startSet = makePairs component.depends;
operator = {val,...}: makePairs val.config.depends;
};
in map ({val,...}: val) closure;
}
7 changes: 7 additions & 0 deletions test/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,11 @@ nix-shell $NIX_BUILD_ARGS \
--run 'cd shell-for && cabal new-build all'
echo >& 2

printf "*** Checking shellFor has a working hoogle index...\n" >& 2
nix-shell $NIX_BUILD_ARGS \
--pure ./default.nix \
-A shell-for.env \
--run 'hoogle ConduitT | grep Data.Conduit'
echo >& 2

printf "\n*** Finished successfully\n" >& 2