I was testing creating a nix derivation for a hare program, however the
build fails with hare throwing the following error message:
> Error creating /homeless-shelter/.cache/hare: Permission denied
The hare command invocation:
> hare build -o <progname>
This happens because in nix's sandbox only certain paths may be written,
i. e., the ones returned by the `placeholder` builtin. Since hare seems
to follow the XDG Path spec[0], and `XDG_CACHE_HOME` is not set, it
defaults to `${HOME}/.cache`, which is not a writable path in the
sandbox.
As a workaround, one may do the following hack, by setting hare's cache
directory inside a writable directory and later deleting it, for it's
not needed for the derivation's output:
```nix
preBuild = ''
export XDG_CACHE_HOME="${placeholder "out"}/.cache"
'';
postBuild = ''
rm -rf "''${XDG_CACHE_HOME}"
'';
```
However, such hack could be avoided if there were a way to disable
hare's caching.
Is disabling the cache already possible?
If not, is there a plan to add it or would it be considered too much of
an edge case, since, as it was shown before, these edge cases may have
their own solutions as hacky as they may be?
[0]: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
--
Cheers,
Coutinho de Souza
I think that following XDG_CACHE_HOME here is the correct behavior for
Hare, and Nix should endeavour to set it to the appropriate value to
ensure the correct behavior.
On Sat Sep 16, 2023 at 1:49 PM UTC, Coutinho de Souza wrote:
> If not, is there a plan to add it or would it be considered too much of> an edge case, since, as it was shown before, these edge cases may have> their own solutions as hacky as they may be?
yeah it's not really possible to disable the cache directory, since we
compile things by filling the cache then copying the cached artifact you
asked for out to the path you asked for it to be output to
I see.
As a simpler solution then to one I've given earlier, one may do the
following:
```nix
preBuild = ''
export HARECACHE="$(mktemp -d)"
'';
```
Now there's no need to delete the cache directory afterwards.