[Haskell-cafe] Using stack outside the project box

Travis Cardwell travis.cardwell at extrema.is
Mon Jun 7 00:10:24 UTC 2021


The Stack configuration that is used outside of projects is stored in
the following location:

    ~/.stack/global-project/stack.yaml

This configuration file is used when you run `stack ghci` outside of a
project.  Such project configuration files can specify the Stackage
snapshot to be used (`resolver`), any packages that should be used that
are different from or not in the specified Stackage snapshot
(`extra-deps`), a list of packages that are being developed (`packages`,
none by default in the "global project"), as well as some other settings
documented at the following location.

https://docs.haskellstack.org/en/stable/yaml_configuration/

Such a project configuration file determines what packages are
*available* for use.  The motivation is to provide an environment where
all of the available packages work together, saving you from having to
deal with dependency conflicts.  It does not *expose* packages to the
compiler or REPL.  Packages are usually exposed by specifying them in a
`.cabal` file (or `package.yaml` file when using hpack).

In my experience, the `~/.stack/global-project/stack.yaml` configuration
is most often used when installing executables using Stack.  For example,
one can install the version of `hlint` that is in the Stackage snapshot
configured in the configuration file as follows:

    stack install hlint

What you would like to do is not normal usage of Stack, but I understand
your motivation.  It is possible to do what you want by configuring a
global project with the packages that you would like to make available.
First, create file `~/.stack/global-project/global-project.cabal` with
the following content:

    name:           global-project
    version:        0.0.0.0
    cabal-version:  1.24
    build-type:     Simple

    library
      build-depends:
          base
        , safe
      default-language: Haskell2010

Add any packages that you would like to expose to the `build-depends`
list.  Next, configure `~/.stack/global-project/stack.yaml` as follows:

    resolver: lts-17.14

    packages:
      - .

Update the `resolver` configuration whenever you want to change Stackage
snapshots.  Note that you will need to add `extra-deps` configuration to
this file if you ever want to expose a package that is not in the
configured snapshot, in addition to adding it to the `build-depends`
list.

With this configuration, the listed packages should be exposed when you
run `stack ghci` to run a REPL.

Good luck!

Travis


More information about the Haskell-Cafe mailing list