cache: Caching `/nix/store` is ok, but unable to restore it.
Hi,
I’m trying to improve the workflow in here: https://github.com/hmemcpy/milewski-ctfp-pdf/blob/master/.github/workflows/build.yaml
Basically I would like to cache the build dependencies once, and re-use them in each book editions (8), so there is no need to download 8 times the same thing.
Caching the /nix/store directory works: https://github.com/drupol/milewski-ctfp-pdf/runs/5348859880?check_suite_focus=true

Restoring it fails: https://github.com/drupol/milewski-ctfp-pdf/runs/5348868521?check_suite_focus=true

Do you have any idea on how I could fix this ?
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 13
- Comments: 15 (2 by maintainers)
Commits related to this issue
- Switch over to using `nix` flakes It seems flakes are going to take over the world, so we're going to try them out for this. The thing that seems actually interesting is that since flakes require th... — committed to joneshf/terraform-provider-openwrt by joneshf 4 years ago
- Switch over to using `nix` flakes It seems flakes are going to take over the world, so we're going to try them out for this. The thing that is actually interesting about this change is that since fl... — committed to joneshf/terraform-provider-openwrt by joneshf 4 years ago
- Fix macos caching issue (#19) ### Description macOS caching is broken. This PR fixes it. This is related to `gtar` not having `sudo` permission, but `/nix/store` requires sudo. There are many many re... — committed to jetify-com/devbox-install-action by LucilleH 3 years ago
If anyone else is like I was just a bit ago and was still looking for a decent solution to this problem, using the
nixcommand–instead of thenix-*commands–can be an option. With thenixcommand, you can pass it a--storeflag to specify an alternate location for the nix store. If you make that location somewhere that the cache action can write–like~/nix–it should allow you to cache your nix store!Depending on what you’re doing, using the
nixcommand might require you to change some stuff around. E.g. I had to switch over to using flakes in https://github.com/joneshf/terraform-provider-openwrt/pull/83 in order to run a similar command. For posterity, I went from runningnix-shell --run 'make test'to runningnix --store ~/nix develop . --command make test; and then caching the~/nixdirectory with thisactions/cacheaction. But if you can switch over to thenixcommand, you might also be able to benefit from this (or a similar) approach.My solution is unnecessarily slow and complicated.
This issue could be resolved easily by running the tar in the creation and untar in the restore with root privileges using sudo. Is this not an acceptable solution?
This would also solve #629 and #324 .
Do you think it would be a good idea to automatized these steps the Github Action (https://github.com/cachix/install-nix-action) from @domenkozar ?
I tried this action before, and it does not work at all. For some reason, it’s not recognized anymore.
@joneshf it’s also possible to set
store = /home/runner/nixinextra_nix_configso that allnixcommands will use that store by default.But I’m unsure if
/home/runneris the canonical path of~on Github Action. I couldn’t find any runner variable that points to the HOME path. There could be a more suitable path to cache the store in rather than~/nix.Nix store caching plus some extra features are implemented in https://github.com/nix-community/cache-nix-action/.
Reading through the thread, looks like there a solution built using https://github.com/cachix/install-nix-action. If there is no requirement on cache action, I will close this issue.