[Haskell-cafe] Using stack outside the project box

Galaxy Being borgauf at gmail.com
Mon Jun 7 21:22:30 UTC 2021


I installed stack on my Windows computer using chocolatey, which went
smoothly. But I had nothing anywhere I could find. On a hunch, at the
prompt I tried to run stack ghci, *then *it started downloading and
installing stuff. Good. I then was able to track down an example of a
stack.yaml in the ...stack/global-project directory. My whole motivation
was to see an actual global stack.yaml in the wild, and not have to
guess-and-test from the stack docs. Good. I duplicated

packages: []
resolver: lts-17.15

on my Ubuntu 21.04 in the .stack/global-project/stack.yaml. Tried running stack
ghci from the Ubuntu prompt, and, similarly, it started installing lots of
stuff. (The resolver version I replaced was lts-17.08. Why that old I don't
know.). But then I got a cryptic error as it seemed to clash or not like
something it saw in some obscure github directory I had cloned ages ago
with Haskell example code. I deleted everything in the github directory
that looked stack/cabal-ish and tried stack ghci again. Now it says

Warning (added by new or init): Some packages were found to have names
conflicting with others and have been commented out in the packages section.
Warning (added by new or init): Some packages were found to be incompatible
with the resolver and have been left commented out in the packages section.
You can omit this message by removing it from stack.yaml

Stack looks for packages in the directories configured in
the 'packages' and 'extra-deps' fields defined in your stack.yaml
The current entry points to /home/galaxybeing/Dropbox/org/HaskellRoad/,
but no .cabal or package.yaml file could be found there.

Yes, that was the directory I purged. My
.stack/global-project/stack.yaml contains
only

packages: []
resolver: lts-17.15

Not sure how to proceed. Seeing how that vast majority of Haskell intro
books don't use projects, just install, start ghci, load code at the REPL
prompt, I'd really like to nail this "global", non-project stack down.




On Sun, Jun 6, 2021 at 7:10 PM Travis Cardwell <travis.cardwell at extrema.is>
wrote:

> 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
>


-- 
⨽
Lawrence Bottorff
Grand Marais, MN, USA
borgauf at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20210607/d1748483/attachment.html>


More information about the Haskell-Cafe mailing list