1# The ghcForComponent function wraps ghc so that it is configured with
2# the package database of all dependencies of a given component.
3# It has been adapted from the ghcWithPackages wrapper in nixpkgs.
5# This wrapper exists so that nix-shells for components will have a
6# GHC automatically configured with the dependencies in the package
9{ lib, stdenv, ghc, runCommand, lndir, makeWrapper, haskellLib
12{ componentName # Full derivation name of the component
13, configFiles # The component's "config" derivation
18 inherit (configFiles) targetPrefix ghcCommand ghcCommandCaps packageCfgDir;
19 libDir = "$out/${configFiles.libDir}";
20 docDir = "$out/share/doc/ghc/html";
21 # For musl we can use haddock from the buildGHC
22 haddock = if stdenv.hostPlatform.isLinux && stdenv.targetPlatform.isMusl && !haskellLib.isNativeMusl
26in runCommand "${componentName}-${ghc.name}-env" {
27 preferLocalBuild = true;
29 inherit (ghc) version meta;
35 . ${makeWrapper}/nix-support/setup-hook
39 ${lndir}/bin/lndir -silent ${ghc} $out
40 # ... remove all of the package directories
42 # ... but retain the lib/ghc/bin directory. This contains `unlit' and friends.
43 ln -s ${ghc}/lib/${ghcCommand}-${ghc.version}/bin ${libDir}
44 # ... and the ghcjs shim's if they are available ...
45 if [ -d ${ghc}/lib/${ghcCommand}-${ghc.version}/shims ]; then
46 ln -s ${ghc}/lib/${ghcCommand}-${ghc.version}/shims ${libDir}
48 # ... and node modules ...
49 if [ -d ${ghc}/lib/${ghcCommand}-${ghc.version}/ghcjs-node ]; then
50 ln -s ${ghc}/lib/${ghcCommand}-${ghc.version}/ghcjs-node ${libDir}
52 # Replace the package database with the one from target package config.
53 ln -s ${configFiles}/${packageCfgDir} $out/${packageCfgDir}
55 # Wrap compiler executables with correct env variables.
56 # The NIX_ variables are used by the patched Paths_ghc module.
58 for prg in ${ghcCommand} ${ghcCommand}i ${ghcCommand}-${ghc.version} ${ghcCommand}i-${ghc.version}; do
59 if [[ -x "${ghc}/bin/$prg" ]]; then
61 makeWrapper ${ghc}/bin/$prg $out/bin/$prg \
62 --add-flags '"-B$NIX_${ghcCommandCaps}_LIBDIR"' \
63 --set "NIX_${ghcCommandCaps}" "$out/bin/${ghcCommand}" \
64 --set "NIX_${ghcCommandCaps}PKG" "$out/bin/${ghcCommand}-pkg" \
65 --set "NIX_${ghcCommandCaps}_DOCDIR" "${docDir}" \
66 --set "NIX_${ghcCommandCaps}_LIBDIR" "${libDir}"
70 for prg in "${targetPrefix}runghc" "${targetPrefix}runhaskell"; do
71 if [[ -x "${ghc}/bin/$prg" ]]; then
73 makeWrapper ${ghc}/bin/$prg $out/bin/$prg \
74 --add-flags "-f $out/bin/${ghcCommand}" \
75 --set "NIX_${ghcCommandCaps}" "$out/bin/${ghcCommand}" \
76 --set "NIX_${ghcCommandCaps}PKG" "$out/bin/${ghcCommand}-pkg" \
77 --set "NIX_${ghcCommandCaps}_DOCDIR" "${docDir}" \
78 --set "NIX_${ghcCommandCaps}_LIBDIR" "${libDir}"
82 # Wrap haddock, if the base GHC provides it.
83 if [[ -x "${haddock}/bin/haddock" ]]; then
84 rm -f $out/bin/haddock
85 makeWrapper ${haddock}/bin/haddock $out/bin/haddock \
86 --add-flags '"-B$NIX_${ghcCommandCaps}_LIBDIR"' \
87 --set "NIX_${ghcCommandCaps}_LIBDIR" "${libDir}"
90 # Point ghc-pkg to the package database of the component using the
91 # --global-package-db flag.
93 for prg in ${ghcCommand}-pkg ${ghcCommand}-pkg-${ghc.version}; do
94 if [[ -x "${ghc}/bin/$prg" ]]; then
96 makeWrapper ${ghc}/bin/$prg $out/bin/$prg --add-flags "--global-package-db=$out/${packageCfgDir}"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list