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

image

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

image

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

Most upvoted comments

If anyone else is like I was just a bit ago and was still looking for a decent solution to this problem, using the nix command–instead of the nix-* commands–can be an option. With the nix command, you can pass it a --store flag 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 nix command 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 running nix-shell --run 'make test' to running nix --store ~/nix develop . --command make test; and then caching the ~/nix directory with this actions/cache action. But if you can switch over to the nix command, 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’m facing a similar issue and only started looking for solutions, but there seem to be actions that manage to use the cache on /nix/store, eg. https://github.com/rikhuijzer/cache-install. I’m just putting this here for documentation purposes and I will come back if I find a solution.

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/nix in extra_nix_config so that all nix commands will use that store by default.

But I’m unsure if /home/runner is 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.