-
Notifications
You must be signed in to change notification settings - Fork 841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add XDG support #5919
Add XDG support #5919
Conversation
@drlkf, many thanks. Am I correct to understand the following?
I think some extension will be needed to the |
My opinion is that this shouldn't be automagic, but the user should set an env var (like |
Mike Pilgrem ***@***.***> wrote:
Am I correct to understand the following?
* this introduces the idea of a 'global config root', distinct from the rest of the traditional Stack root
This is correct, as discussed in #4243 XDG introduces separation of
concerns that is not yet present in `stack`.
* if the `STACK_ROOT` environment variable is defined, then that is respected as both the Stack root and the 'global config root'
* if the traditional Stack root already exists, that is respected as both the Stack root and the 'global config root'
* otherwise, if the `XDG_DATA_HOME` and `XDG_CONFIG_HOME` environment variables exist, the former is used as the base for Stack root and the latter as the base for the 'global config root'.
Correct, XDG is pretty much the last option `stack` would resort to,
when everything else has been ruled out.
* otherwise, if the `XDG_DATA_HOME` and `XDG_CONFIG_HOME` environment variables exist, the former is used as the base for Stack root and the latter as the base for the 'global config root'.
* otherwise, `%APPDIR%\stack` is used on Windows (as before); and `~/.local/share` and `~/.config` are used on Unix-like operating systems (a change in Stack's behaviour).
Correct, if you meant `%APPDATA%\stack` for Windows.
I think some extension will be needed to the `stack path` command, as `stack path --stack-root` will no longer help the user to know where the 'global config root' is located. Perhaps a `stack path --global-config` command? (I refer to 'global config' because the existing `stack path --config-location` refers to the project-level YAML configuration file.)
I have added it to the best of my ability in 6054fd1, let me know if
something is missing/wrong.
|
@drlkf, many thanks for the explanations. I think @hasufell is correct at #5919 (comment). A lot of CI will currently assume it has to cache |
Mike Pilgrem ***@***.***> wrote:
I think @hasufell is correct at #5919 (comment). A lot of CI will currently assume it has to cache `~/.stack` on Linux and so some express 'opt-in' for a shift to `~/.local/share/stack` and `~.config/stack` might, at the least, smooth the introduction. The presence of the environment variable `STACK_XDG` seems like a way to do that. (GHCup uses `GHCUP_USE_XDG_DIRS` - https://www.haskell.org/ghcup/guide/#xdg-support, by way of another example.)
Seems sensible to me, I've added this change, and the documentation and
changelog entries. Could you tell me if those are ok ?
|
Looks good to me! Thanks. |
I may be a bit late to the party, but it seems that This description of the XDG spec sums up the distinction:
Deleting everything, excepting the config and templates, only means re-downloading a bunch of stuff on future Stack runs, which makes it cache. On the other hand, |
@galenhuntington, this development was said to introduce 'basic' XDG support, and It is perhaps debatable whether the implicit global project (the project-level configuration file of 'last resort') is conceptually application 'configuration'. On the one hand it is common to all projects that do not have another project-level configuration file in their ancestry. On the other hand, it is a project-level configuration file, like any other. As for 'non-essential' data files (cache), I suppose 'essential', like beauty, can be in the eye of the beholder. Yes, Stack can rebuild things if it needs to, but in some cases that would involve a lot of compiling - the 'cost' of losing the 'snapshot' data might be felt keenly by some. |
I'd say that's a central example of cache. Cached files are useful, sometimes very useful, to have around but can always be reconstituted. It's not like losing your PhD thesis or baby pictures. A criterion is what to back up. If you're archiving to Tarsnap, there's bandwidth and storage cost to keeping tens of gigs around for years, and if your drive crashes, it is not necessarily more convenient to restore from back-up than to rebuild with Stack. Indeed, in the case of Stack, I recompile often anyway, such as when GHC is bumped, and my I agree it would be good to get the XDG layout right before it gets wide adoption. Sure, it's not always clear-cut what's config (vs. data or state), and despite using Stack for years I still feel I don't understand a lot of fine points. If I had to spitball a backward-compatible solution, I'd suggest using XDG directories going forward, but for new installs, unless overridden by something like |
This patch implements basic XDG support, as requested in #4243, with the
following logic:
~/.stack
directory exists, use it.config.yaml
in a subdirectory ofXDG_CONFIG_HOME
, and the rest in a subdirectory ofXDG_DATA_HOME
.I tested this in a clean VM with no prior
stack
installed, with the following commands:Backwards-compatibility test:
Although this is not much, I think it's indicative enough that
stack
isreading/writing files in the correct locations. If the maintainers think written
tests need to be added, I am open to suggestions.
Some typo fixed while reading
CONTRIBUTING.md
too! :o)A
TODO
comment asks if somePath.IO
exception should be handled because Idon't know what is the general expected behavior of
stack
here.There are several other problems and questions that I'm unable to answer alone:
maintainers. For instance, it seems Travis caching will be broken by this
change. I don't know your policy about this kind of questions.
behavior should be documented and, if XDG becomes default, I personally don't
think legacy behavior should be cluttering the documentation.
unfamiliar with this OS. If you have a standard way, I'm open to suggestions.