Skip to content

Add config flag to control generation of .ghc.environment files #4542

Closed

Description

@hvr

Some people are excited about .ghc.environment files, while others are mildly annoyed. I think there's probable cause to make this configurable on cabal's end.

To this end, I suggest (modulo bikeshed) to implement a flag, e.g. --pkg-environment-scope=LEVEL, where LEVEL can be one of

  1. all (default & current behaviour, generate ghc env files with all transitive dependencies of project's (non-qualified) goals)
  2. build-target (e.g. :pkg:Cabal or lib:Cabal or Cabal:test:parser-tests): generate ghc env files containing only the stated goal's /direct/ dependencies)
  3. - (or none or off or disable?): disable generation of any ghc env files

This flag would also be persistable via cabal.project.(local).

Note: Item 2. is not the short-term goal of this feature request! I've included the 2. item mostly to motivate why it makes sense to design this to be a flag that's more than merely a boolean --{disable,enable}-package-environment-files flag.

Btw, a dual feature-request (allowing to opt-out from interpreting .ghc.environment files from GHC's side) has been filed at GHC #13753 -- however, that one will be too late for GHC 8.0.2 users.

Current status:

/cc @RyanGlScott

Activity

  1. added
    cabal-install: v2-build system
    on May 27, 2017
  2. ezyang commented on May 28, 2017

    @ezyang
    Contributor

    So, I've recently been working in the Python/Anaconda world, where they have scripts like source activate myenv which kick you into an alternate shell where when you call python, you get the environment (interpreter, packages, etc) correspond to the particular environment you are working on. Letting this setting be done on a per shell basis seems better to me than setting it to file path location? (Yes, I know this is totally asking GHC environments to be redone, but it seems to me like it would solve the root cause of the problem you're describing above, as well as other problems.)

  3. hvr commented on May 29, 2017

    @hvr
    MemberAuthor

    Tbh, I have been working with Python's virtualenvs for quite some time, and they were somewhat unsatisfying to me. I prefer the git-style approach which has been copied by many tools which are $CWD sensitive. I don't want to have to remember and having to explicitly perform redundant keystrokes to enter an environment other than simply cding into a project, and have my tool follow the DWIM principle. If we require to explicitly enter environments, we still have cabal exec or cabal repl; but that's a different paradigm (which has its uses) from what GHC environment files provide. Since GHC environments started working in cabal head, I've reduced my use of cabal new-repl to quite a lot less.

    This ticket is primarily to help those who don't subscribe to that paradigm, and want to opt-out.

  4. alanz commented on Jun 19, 2017

    @alanz
    Collaborator

    I just spent a significant chunk of time trying to get a project to build and run tests, using stack. I build the project using both cabal master and stack, to check that it works for both.

    Having deleted the dist* directories and built with stack, the tests failed, complaining about a missing package db in ./dist-newstyle.

    After re-installing everything haskell related, I eventually tracked it down to this file being silently generated, and then being picked up by other tools.

    At this stage I would prefer to opt in for this generation, or at least get something in the output to say that the file has been generated, so that I can know that a potential landmine has been planted.

    This is bound to trip up others as well, as the existence and use of this file is not well documented.

  5. added this to the 2.2 milestone on Jun 19, 2017
  6. ezyang commented on Jul 6, 2017

    @ezyang
    Contributor

    I agree that this state of affairs is not great. @hvr, can we perhaps change this setting to be opt-in?

  7. 23Skidoo commented on Jul 6, 2017

    @23Skidoo
    Member

    Can we get stack to turn off parsing of .ghc.environment files with -hide-all-packages?

    /cc @mgsloan

  8. cocreature commented on Aug 2, 2017

    @cocreature
    Collaborator

    fwiw nix also breaks in some cases due to .ghc.environment.* files so I don’t think that a workaround in stack is the right solution here.

  9. gbaz commented on May 12, 2018

    @gbaz
    Collaborator

    As per https://www.reddit.com/r/haskell/comments/8iyvoo/psa_for_cabal_22_new_users_regarding/ I think that the weight of opinion is that these files should not be auto-generated, but only by opt-in.

    If we add this flag as a global flag that can be in ~/.cabal/config and off by default then that would help. Then if people wanted such a config, they could run cabal new-configure --package-environment-scope=ALL.

    I think that would improve the situation for a whole bunch of workflows...

  10. hvr commented on May 13, 2018

    @hvr
    MemberAuthor

    @gbaz quite honestly, I'm strongly against defaulting it off, as then nobody would even use what I consider one of the biggest improvements over the old flawed user pkg-db model, since almost nobody would know about it ;-(

    Before changing anything, I'd rather want to know exactly what workflows we're talking about that people are having problems with, as I suspect the issues are of a different nature...

    Fwiw, there's already patches up at

    to address some of the concerns with the UI

  11. 112 remaining items

  12. joneshf commented on Oct 15, 2018

    @joneshf

    Since it looks like we're not getting a flag any time soon, can we get some help on the proper way to work with these files?

    Here's my current situation that's breaking:

    1. I use nix to bring in cabal-install and shake
    2. I setup a Shakefile.hs with one rule, build, to run cabal new-build all:
      import Development.Shake (cmd_, phony, shake)
      
      main :: IO ()
      main = shake (phony "build" (cmd_ "cabal new-build all"))
    3. I run shake build
    4. It works once, but creates an environment file
    5. I run shake build again
    6. shake won't run because it picks up the environment file, but the environment file didn't list shake as a package, and it cannot find Development.Shake.

    What am I doing wrong, and how am I supposed to make this work with new-build?

  13. ElvishJerricco commented on Oct 15, 2018

    @ElvishJerricco

    Sounds like Shake needs to be fixed to ignore package environments when it invokes GHC, just like the various other tools that have had to make changes for this.

    Personally, I see that as very frustrating. The author of every tool that invokes GHC has to be aware of the fact that they have to add the same magic lines as everyone else in order for their tool not to break with new-build. I really don't think GHC should pick these up automagically.

  14. phadej commented on Oct 15, 2018

    @phadej
    Collaborator

    OTOH tools like liquid greatly benefit from GHC (as the lib) automatically picking up the environment.

  15. svenpanne commented on Oct 15, 2018

    @svenpanne

    I don't want to repeat the all the lengthy stuff I and other people have already written about the reasons why forcing tons of tools to opt-out is a bad idea compared to a structured way to opt-in (the pipenv runway), just this: The recent comments in this issue seem to enforce this point of view. :-/ I really fail to understand why people generally think that explicit is better than implict, but take the very opposite view in the case at hand...

  16. lspitzner commented on Oct 15, 2018

    @lspitzner
    Collaborator

    @phadej So my time was wasted for the benefit of liquid users? Where exactly can I send my invoice for the time invested to fix my workflow?

  17. lspitzner commented on Oct 15, 2018

    @lspitzner
    Collaborator

    @phadej That you keep repeating the "but it is useful" argument is just pissing me of. It is highly disrespectful to the users affected negatively. It is highly frustrating that the maintainership makes such a one-sided, private, authoritarian decision on whether breaking existing workflows is justified by convenience for certain users.

  18. athas commented on Oct 15, 2018

    @athas
    Collaborator

    There is no reason to become so hostile. I, too, think that the implicit loading of environment files is a misfeature and would prefer if I had to use some explicit cabal exec mechanism to pick them up. However, I do not know whether that is the majority opinion. It seems so from this thread, but the people who are happy with the current behaviour may simply not participate.

    Ultimately, however, the maintainers of GHC and Cabal get to make the decision (as they should), and since they seem to prefer the implicit behaviour, we should probably just accept it, and start fixing our tools. In particular, unless someone is actually motivated enough to write code to change the current behaviour, then it will eventually just become a fait accompli due to inertia.

  19. ElvishJerricco commented on Oct 15, 2018

    @ElvishJerricco

    I dunno. I'm not a fan of the idea that GHC and Cabal should service the GHC and Cabal developers before GHC and Cabal users.

  20. lspitzner commented on Oct 15, 2018

    @lspitzner
    Collaborator

    There is no reason to become so hostile.

    What are you referring to? Please, if you make those kind of accusations, be explicit in what and who you address.

  21. gbaz commented on Oct 15, 2018

    @gbaz
    Collaborator

    @joneshf

    I think that adding a second rule to shake that deletes the env file after the build is complete might work?

    I like many am waiting for the new cabal-install release including this flag, and hope it comes soon, to coincide with the pending ghc 8.6.2 bugfix release.

  22. joneshf commented on Oct 15, 2018

    @joneshf

    @gbaz Thanks! I'd tried that earlier with runAfter, but it didn't seem to remove the file. After taking some time (and re-inspired by your suggestion), I ended up with:

    main = shake shakeOptions $ do
      phony "build" $ do
        cmd_ "cabal new-build all"
        removeFile "" [".ghc.environment*"]

    Posted for posterity/completeness. Hopefully it helps the next person that gets bit by this bug.

  23. mankyKitty commented on Nov 9, 2018

    @mankyKitty

    I agree that some sort of flag is needed to control whether or not this file is used. However I would err on the opt out side of things, as I see myself as not really being the 'common use-case'.

    For the sake of people looking for similar answers, I wrote the following function in my emacs config to help manage it:

      (defun remove-ghc-env-file-then (f)
        (shell-command-to-string (concat "rm " (projectile-project-root) ".ghc.environment.x86_64-linux-*"))
        f
        )
  24. nomeata commented on Nov 18, 2018

    @nomeata
    Contributor

    Not sure how helpful it is to amend to this already very long thread, but I feel that this point is not addressed here:

    Cabal provides the very useful flag --distdir that I can use to maintain two separate “contexts” of the same project – maybe different dependencies, different build flags etc. But this seems to be inherently incompatible with creating a GHC environment file that lives outside the distdir: It would unpredictably refer to the distdir that I used last? (The environment filename encodes the compiler used, but not any of the other ways cabal configurations could differ.)

    Hence my expectation indeed is that cabal never touched files outside of dist-newstyle/ (or whatever distdir I configure), and that whenever I want to do something “in the context of a configured Cabal projects”, I expect to use one of the cabal commands.

  25. added a commit that references this issue on Nov 23, 2018
    0e27a4d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions