Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Output cabal-store: Use XDG directory structure for cabal 3.10? #210

Closed
Tracked by #6521
andreasabel opened this issue Mar 15, 2023 · 8 comments · Fixed by #213
Closed
Tracked by #6521

Output cabal-store: Use XDG directory structure for cabal 3.10? #210

andreasabel opened this issue Mar 15, 2023 · 8 comments · Fixed by #213
Assignees
Labels
bug Something isn't working re: cabal On setting up cabal workaround exists
Milestone

Comments

@andreasabel
Copy link
Member

andreasabel commented Mar 15, 2023

Newly released cabal 3.10.1.0 uses the XDG directory structure unless a ~/.cabal is already present.
From https://github.com/haskell/cabal/blob/master/release-notes/cabal-install-3.10.1.0.md#significant-changes:

Cabal/cabal-install now uses the XDG Base Directory Specification to store configuration, caches, and the store. Specifically,$XDG_CONFIG_HOME/cabal stores the configuration file,$XDG_CACHE_HOME/cabal stores downloaded packages and similar, and $XDG_STATE_HOME/cabal mainly contains the store of compiled packages. Further, cabal install will put executables in ~/.local/bin by default.

The dist/dist-newstyle directories are not affected.

On Windows, these XDG paths are mapped to other (hopefully) appropriate locations. See the Cabal User Guide for information.

If the CABAL_DIR environment variable is set, the indicated directory will be used to store all Cabal-related files, as in previous versions.

Backwards compatibility: If ~/.cabal already exists, this will be interpreted as CABAL_DIR=~/.cabal. This means that upgrading on an existing system already using cabal-install should not cause any change in behaviour. An existing system can be migrated by deleting ~/.cabal (possibly copying ~/.cabal/config to ~/.config/cabal/config first).

We likely need to adapt the cabal-store output to respect this change or make sure stuff lands in ./~cabal as it used to be:

if (process.platform === 'win32') {
fs.appendFileSync(configFile, `store-dir: C:\\sr${EOL}`);
core.setOutput('cabal-store', 'C:\\sr');
} else {
core.setOutput('cabal-store', `${process.env.HOME}/.cabal/store`);
// Issue #130: for non-choco installs, add ~/.cabal/bin to PATH
const installdir = `${process.env.HOME}/.cabal/bin`;

Upstream issue:

@andreasabel
Copy link
Member Author

Caching failure due to this problem in the wild:

@andreasabel andreasabel added the bug Something isn't working label Mar 16, 2023
@andreasabel
Copy link
Member Author

andreasabel commented Mar 16, 2023

Workaround: mkdir -p ~/.cabal before running the setup action.
See e.g.: agda/agda@c5f700c :

    steps:
    - uses: actions/checkout@v3

    - name: Switch off XDG directories for cabal (Linux)
      if: ${{ runner.os == 'Linux' }}
      run: |
        mkdir -p ~/.cabal
      # The presence of ~/.cabal switches cabal 3.10 to not use the XDG layout.

    - uses: haskell/actions/setup@v2

@athas
Copy link

athas commented Mar 16, 2023

I believe setting CABAL_DIR=$HOME/.cabal is the cleanest solution. CI tools don't benefit from the XDG split anyway, and perhaps ten years from now the backwards compatibility based on ~/.cabal existing may be removed.

@andreasabel
Copy link
Member Author

@athas wrote:

I believe setting CABAL_DIR=$HOME/.cabal is the cleanest solution.

Thanks!

@Mikolaj @ulysses4ever If I integrate CABAL_DIR=$HOME/.cabal into the setup action, then we won't be able to CI the XDG feature for cabal. Opinions?

andreasabel added a commit that referenced this issue Mar 16, 2023
We set the `store-dir` (`outputs.cabal-store`) explicitly in the cabal configuration file
because cabal 3.10 has some context-dependent default for it:
If `~/.cabal` is not present, it uses the new XDG layout, otherwise not.
@Mikolaj
Copy link
Member

Mikolaj commented Mar 16, 2023

@Mikolaj @ulysses4ever If I integrate CABAL_DIR=$HOME/.cabal into the setup action, then we won't be able to CI the XDG feature for cabal. Opinions?

Please go ahead. When we want to switch to XDG, we'll find a way around, e.g., we'd empty the env variable.

@ulysses4ever
Copy link
Contributor

This option was meant to be disruptive. (In the hindsight, haskell/cabal#8577 perhaps had a good idea for managing some of the disruption.) In the interest of damage management, I'd say, forcing the old way in the CI sounds fine. Maybe a more principled solution would be to make another action parameter for whether or not to do what you suggest (and by default indeed do that). Although, not many users would be interested in such partner, perhaps, and it's a code that you need to maintain... All in all, it's your call. Erroring on the safe side is perhaps preferable.

@ulysses4ever
Copy link
Contributor

e.g., we'd empty the env variable

Well, I'm afraid if the action explicitly set it, we won't be able to do anything. Except, as I do in haskell/cabal#8840, opt out of cabal update in the action altogether.

andreasabel added a commit that referenced this issue Mar 16, 2023
…213)

We set the `store-dir` (`outputs.cabal-store`) explicitly in the cabal configuration file because cabal 3.10 has some context-dependent default for it: If `~/.cabal` is not present, it uses the new XDG layout, otherwise the legacy layout.

Update: Also need to create `~/.cabal` to avoid XDG fallback, so we create `~/.cabal/bin`.  Likely this makes the "set `store-dir`" patch obsolete, but we keep it for uniformity (it anyway happens on Windows, now on all platforms).

CI update: Make sure we test Linux + cabal-3.10 with `cabal-update` to catch problems with confusion about the directory layout (XDG or not).

Closes #210.
@andreasabel
Copy link
Member Author

andreasabel commented Mar 16, 2023

For now, I settled for the workaround that creates ~/.cabal, because this fits more smoothly into the current code of the action.
If we need some parametrization, we can add it later. For now, I just worry to extinguish the wildfires.

Released as latest and v2 (not yet as v2.3 or v2.3.6).

@andreasabel andreasabel self-assigned this Mar 16, 2023
@andreasabel andreasabel added this to the 2.3.6 milestone Mar 16, 2023
jgm added a commit to jgm/pandoc that referenced this issue Jun 28, 2023
The GitHub action now uses `$XDG_STATE_HOME/cabal`, which is
why our cache wasn't working.

See haskell/actions#210
9999years pushed a commit to 9999years/haskell-actions that referenced this issue Mar 27, 2024
…10 XDG (haskell#213)

We set the `store-dir` (`outputs.cabal-store`) explicitly in the cabal configuration file because cabal 3.10 has some context-dependent default for it: If `~/.cabal` is not present, it uses the new XDG layout, otherwise the legacy layout.

Update: Also need to create `~/.cabal` to avoid XDG fallback, so we create `~/.cabal/bin`.  Likely this makes the "set `store-dir`" patch obsolete, but we keep it for uniformity (it anyway happens on Windows, now on all platforms).

CI update: Make sure we test Linux + cabal-3.10 with `cabal-update` to catch problems with confusion about the directory layout (XDG or not).

Closes haskell#210.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working re: cabal On setting up cabal workaround exists
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants