-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from input-output-hk/builder-haddock
Dev environments
- Loading branch information
Showing
23 changed files
with
731 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# This is a simplified version of the ghcWithPackages wrapper in | ||
# nixpkgs, adapted to work with the package database of a single | ||
# component. | ||
{ lib, stdenv, ghc, runCommand, lndir, makeWrapper | ||
}: | ||
|
||
{ package | ||
, configFiles | ||
, postBuild ? "" | ||
}: | ||
|
||
let | ||
isGhcjs = ghc.isGhcjs or false; | ||
ghcCommand' = if isGhcjs then "ghcjs" else "ghc"; | ||
ghcCommand = "${ghc.targetPrefix}${ghcCommand'}"; | ||
ghcCommandCaps= lib.toUpper ghcCommand'; | ||
libDir = "$out/lib/${ghcCommand}-${ghc.version}"; | ||
docDir = "$out/share/doc/ghc/html"; | ||
packageCfgDir = "${libDir}/package.conf.d"; | ||
|
||
in runCommand "${ghc.name}-with-${package.identifier.name}" { | ||
preferLocalBuild = true; | ||
passthru = { | ||
inherit (ghc) version meta; | ||
baseGhc = ghc; | ||
inherit package; | ||
}; | ||
} ( | ||
'' | ||
. ${makeWrapper}/nix-support/setup-hook | ||
# Start with a ghc... | ||
mkdir -p $out/bin | ||
${lndir}/bin/lndir -silent ${ghc} $out | ||
# ...and replace package database with the one from target package config. | ||
rm -rf ${libDir} | ||
mkdir -p ${libDir} | ||
ln -s ${configFiles}/package.conf.d ${packageCfgDir} | ||
# Wrap compiler executables with correct env variables. | ||
# The NIX_ variables are used by the patched Paths_ghc module. | ||
# The GHC_ENVIRONMENT variable forces ghc to use the build | ||
# dependencies of the component. | ||
for prg in ${ghcCommand} ${ghcCommand}i ${ghcCommand}-${ghc.version} ${ghcCommand}i-${ghc.version} runghc runhaskell; do | ||
if [[ -x "${ghc}/bin/$prg" ]]; then | ||
rm -f $out/bin/$prg | ||
makeWrapper ${ghc}/bin/$prg $out/bin/$prg \ | ||
--set "NIX_${ghcCommandCaps}" "$out/bin/${ghcCommand}" \ | ||
--set "NIX_${ghcCommandCaps}PKG" "$out/bin/${ghcCommand}-pkg" \ | ||
--set "NIX_${ghcCommandCaps}_DOCDIR" "${docDir}" \ | ||
--set "NIX_${ghcCommandCaps}_LIBDIR" "${libDir}" \ | ||
--set "${ghcCommandCaps}_ENVIRONMENT" "${configFiles}/ghc-environment" | ||
fi | ||
done | ||
# Point ghc-pkg to the package database of the component using the | ||
# GHC_PACKAGE_PATH variable. | ||
for prg in ${ghcCommand}-pkg ${ghcCommand}-pkg-${ghc.version}; do | ||
if [[ -x "${ghc}/bin/$prg" ]]; then | ||
rm -f $out/bin/$prg | ||
makeWrapper ${ghc}/bin/$prg $out/bin/$prg \ | ||
--set "${ghcCommandCaps}_PACKAGE_PATH" "${configFiles}/package.conf.d" | ||
fi | ||
done | ||
# fixme: check if this is needed | ||
# haddock was referring to the base ghc, https://github.com/NixOS/nixpkgs/issues/36976 | ||
if [[ -x "${ghc}/bin/haddock" ]]; then | ||
rm -f $out/bin/haddock | ||
makeWrapper ${ghc}/bin/haddock $out/bin/haddock \ | ||
--set "NIX_${ghcCommandCaps}_LIBDIR" "${libDir}" | ||
fi | ||
'' | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# `ghcWithPackages` wrapper removal | ||
|
||
The current [Nixpkgs Haskell infrastructure][nixpkgs-haskell] and `haskell.nix` both | ||
provide a `ghcWithPackages` derivation which contains shell script | ||
wrappers that wrap `ghc` and `ghc-pkg`. | ||
|
||
In the Nixpkgs Haskell infrastructure, the wrapper scripts are used | ||
for building Haskell packages. However, in `haskell.nix`, the wrappers | ||
are only used for development environments. | ||
|
||
The wrapper scripts provide a `ghc` command that "knows" about the | ||
package set and has all Haskell package dependencies available to it. | ||
|
||
We would like to remove the wrapper scripts, but it's currently not | ||
possible to configure all build tools using environment variables | ||
alone. | ||
|
||
## Plain `ghc` | ||
|
||
When using `ghc` or `ghci` by itself, the `GHC_ENVIRONMENT` variable | ||
can point to a configuration file containing an exact package | ||
set. This works quite well. | ||
|
||
## `ghc-pkg` | ||
|
||
The package tool `ghc-pkg` does not recognize `GHC_ENVIRONMENT`, but | ||
does recognize a `GHC_PACKAGE_PATH` pointing to a `package.conf.d`. | ||
|
||
This works well. However, the `cabal` command will refuse to start if | ||
`GHC_PACKAGE_PATH` is set. | ||
|
||
## `Setup.hs` | ||
|
||
When invoking `Setup.hs configure`, the package database is provided | ||
with the `--package-db` argument and exact dependencies in the package | ||
set can be provided as `--dependency` arguments. | ||
|
||
The `haskell.nix` component builder uses `Setup.hs` with these | ||
command-line options to build Haskell packages. | ||
|
||
## `cabal new-build` | ||
|
||
Cabal-install will observe the `CABAL_CONFIG` environment variable, | ||
which points to a cabal config file. This config file can provide a | ||
`package-db` value, but it can't specify exact versions of packages. | ||
|
||
Cabal is designed to solve dependencies, not simply take the package | ||
set which is given to it. | ||
|
||
Therefore, `cabal` does not use `GHC_ENVIRONMENT`, but instead creates | ||
its own environment file. It will not accept `--dependency` arguments. | ||
|
||
As far as I know, the best way to force `cabal` to take a pre-computed | ||
package set is to use a `new-freeze` file. However there is no | ||
environment variable (or config file entry) which can specify a path | ||
to a freeze file. | ||
|
||
Specifying a `package-db` path in the cabal config file is not enough | ||
for it to successfully resolve dependencies. | ||
|
||
As mentioned before, `cabal` does not work when `GHC_PACKAGE_PATH` is | ||
set. The best way to work around this is to wrap `ghc` and `ghc-pkg` | ||
in shell scripts. | ||
|
||
|
||
[nixpkgs-haskell]: https://nixos.org/nixpkgs/manual/#users-guide-to-the-haskell-infrastructure |
Oops, something went wrong.