on e94de40 help sign in
haskell.nix/docs/dev/removing-with-package-wrapper.md
66 lines 2.5 kB history raw
1# `ghcWithPackages` wrapper removal
3The current [Nixpkgs Haskell infrastructure][nixpkgs-haskell] and `haskell.nix` both
4provide a `ghcWithPackages` derivation which contains shell script
5wrappers that wrap `ghc` and `ghc-pkg`.
7In the Nixpkgs Haskell infrastructure, the wrapper scripts are used
8for building Haskell packages. However, in `haskell.nix`, the wrappers
9are only used for development environments.
11The wrapper scripts provide a `ghc` command that "knows" about the
12package set and has all Haskell package dependencies available to it.
14We would like to remove the wrapper scripts, but it's currently not
15possible to configure all build tools using environment variables
16alone.
18## Plain `ghc`
20When using `ghc` or `ghci` by itself, the `GHC_ENVIRONMENT` variable
21can point to a configuration file containing an exact package
22set. This works quite well.
24## `ghc-pkg`
26The package tool `ghc-pkg` does not recognize `GHC_ENVIRONMENT`, but
27does recognize a `GHC_PACKAGE_PATH` pointing to a `package.conf.d`.
29This works well. However, the `cabal` command will refuse to start if
30`GHC_PACKAGE_PATH` is set.
32## `Setup.hs`
34When invoking `Setup.hs configure`, the package database is provided
35with the `--package-db` argument and exact dependencies in the package
36set can be provided as `--dependency` arguments.
38The `haskell.nix` component builder uses `Setup.hs` with these
39command-line options to build Haskell packages.
41## `cabal new-build`
43Cabal-install will observe the `CABAL_CONFIG` environment variable,
44which points to a cabal config file. This config file can provide a
45`package-db` value, but it can't specify exact versions of packages.
47Cabal is designed to solve dependencies, not simply take the package
48set which is given to it.
50Therefore, `cabal` does not use `GHC_ENVIRONMENT`, but instead creates
51its own environment file. It will not accept `--dependency` arguments.
53As far as I know, the best way to force `cabal` to take a pre-computed
54package set is to use a `new-freeze` file. However there is no
55environment variable (or config file entry) which can specify a path
56to a freeze file.
58Specifying a `package-db` path in the cabal config file is not enough
59for it to successfully resolve dependencies.
61As mentioned before, `cabal` does not work when `GHC_PACKAGE_PATH` is
62set. The best way to work around this is to wrap `ghc` and `ghc-pkg`
63in shell scripts.
66[nixpkgs-haskell]: https://nixos.org/nixpkgs/manual/#users-guide-to-the-haskell-infrastructure