Repository navigation
Description
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
all(default & current behaviour, generate ghc env files with all transitive dependencies of project's (non-qualified) goals)- build-target (e.g.
:pkg:Cabalorlib:CabalorCabal:test:parser-tests): generate ghc env files containing only the stated goal's /direct/ dependencies) -(ornoneoroffordisable?): 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:
- Starting with GHC 8.4.3, ghc is more verbose when picking up pkg envs (see http://git.haskell.org/ghc.git/commit/00049e2dce93b1e468c3fde3287371eb988aafdc)
- Starting with GHC 8.4.4, ghc supports the special
-environment which inhibits the default lookup logic (see http://git.haskell.org/ghc.git/commit/8f3c149d94814e4f278b08c562f06fc257eb3c43)
/cc @RyanGlScott
Activity
ezyang commentedon May 28, 2017
So, I've recently been working in the Python/Anaconda world, where they have scripts like
source activate myenvwhich kick you into an alternate shell where when you callpython, 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.)hvr commentedon May 29, 2017
Tbh, I have been working with Python's
virtualenvs for quite some time, and they were somewhat unsatisfying to me. I prefer thegit-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 simplycding into a project, and have my tool follow the DWIM principle. If we require to explicitly enter environments, we still havecabal execorcabal 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 ofcabal new-replto quite a lot less.This ticket is primarily to help those who don't subscribe to that paradigm, and want to opt-out.
alanz commentedon Jun 19, 2017
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.
ezyang commentedon Jul 6, 2017
I agree that this state of affairs is not great. @hvr, can we perhaps change this setting to be opt-in?
23Skidoo commentedon Jul 6, 2017
Can we get stack to turn off parsing of
.ghc.environmentfiles with-hide-all-packages?/cc @mgsloan
cocreature commentedon Aug 2, 2017
fwiw nix also breaks in some cases due to
.ghc.environment.*files so I don’t think that a workaround instackis the right solution here.gbaz commentedon May 12, 2018
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...
hvr commentedon May 13, 2018
@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
112 remaining items
joneshf commentedon Oct 15, 2018
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:
cabal-installandshakeShakefile.hswith one rule,build, to runcabal new-build all:shake buildshake buildagainshakewon't run because it picks up the environment file, but the environment file didn't listshakeas a package, and it cannot findDevelopment.Shake.What am I doing wrong, and how am I supposed to make this work with
new-build?ElvishJerricco commentedon Oct 15, 2018
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.
phadej commentedon Oct 15, 2018
OTOH tools like
liquidgreatly benefit from GHC (as the lib) automatically picking up the environment.svenpanne commentedon Oct 15, 2018
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...lspitzner commentedon Oct 15, 2018
@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?
lspitzner commentedon Oct 15, 2018
@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.
athas commentedon Oct 15, 2018
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 execmechanism 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.
ElvishJerricco commentedon Oct 15, 2018
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.
lspitzner commentedon Oct 15, 2018
What are you referring to? Please, if you make those kind of accusations, be explicit in what and who you address.
gbaz commentedon Oct 15, 2018
@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.
joneshf commentedon Oct 15, 2018
@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:Posted for posterity/completeness. Hopefully it helps the next person that gets bit by this bug.
mankyKitty commentedon Nov 9, 2018
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 outside 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:
nomeata commentedon Nov 18, 2018
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
--distdirthat 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 whateverdistdirI 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.Add a --write-ghc-environment-files setting.