-
Notifications
You must be signed in to change notification settings - Fork 80
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
Cache /nix/store between jobs #56
Comments
Hmm, I'm giving that a try, but as far as I understand, that will use Cachix as a binary cache for stuff that is build from source. In my case, I just want to save time downloading binaries from Nixpkgs, keeping already a local copy using the Github Actions cache store. Will Cachix also do that? (Does not look like it from looking at it's code, but I'm not sure.) |
That's not much of an improvement, either way all that content needs to be downloaded to the runner. Unless you self-host the runner. |
Ok, thank you for your reponse! I am using Cachix now and it has still cut a couple of minutes off my actions. Thanks a lot for the great work supporting this great service and your overall contributions to the Nix ecosystem! ❤️ |
❤️ |
For posterity: FYI this is the setup I came up with that (currently) works to cache the plain But it overcomes: 1) the permission errors you get when trying to untar the stored cache on the second run, and 2) the storing part trying to persist lock files and else which will result in permission errors.
|
That's pretty cool, thanks @robinp ! |
I'd followed this but always got the following error when saving the nix packages to the cache |
Squashed commit of the following: commit be261f9005d7f0382bd28e384542e141d47c4c35 Author: Peter Becich <[email protected]> Date: Wed Jun 1 20:17:02 2022 -0700 Revert "test" This reverts commit 678a1ed. commit 678a1ed Author: Peter Becich <[email protected]> Date: Wed Jun 1 19:47:10 2022 -0700 test commit 7c8b2ee Author: Peter Becich <[email protected]> Date: Wed May 25 18:55:42 2022 -0700 use Cachix in GitHub Action commit b99b637 Author: Peter Becich <[email protected]> Date: Tue May 24 00:17:53 2022 -0700 attempt to fix Github Actions caching commit 49f09ed Author: Peter Becich <[email protected]> Date: Mon May 23 19:40:27 2022 -0700 attempt to cache `/nix` in Nix Shell Github Action cachix/install-nix-action#56 (comment) commit 5a5b310 Author: Peter Becich <[email protected]> Date: Mon May 23 19:35:18 2022 -0700 attempt to use cache in Nix Shell Github Action https://github.com/cachix/install-nix-action#how-do-i-add-a-binary-cache
Squashed commit of the following: commit be261f9005d7f0382bd28e384542e141d47c4c35 Author: Peter Becich <[email protected]> Date: Wed Jun 1 20:17:02 2022 -0700 Revert "test" This reverts commit 678a1ed. commit 678a1ed Author: Peter Becich <[email protected]> Date: Wed Jun 1 19:47:10 2022 -0700 test commit 7c8b2ee Author: Peter Becich <[email protected]> Date: Wed May 25 18:55:42 2022 -0700 use Cachix in GitHub Action commit b99b637 Author: Peter Becich <[email protected]> Date: Tue May 24 00:17:53 2022 -0700 attempt to fix Github Actions caching commit 49f09ed Author: Peter Becich <[email protected]> Date: Mon May 23 19:40:27 2022 -0700 attempt to cache `/nix` in Nix Shell Github Action cachix/install-nix-action#56 (comment) commit 5a5b310 Author: Peter Becich <[email protected]> Date: Mon May 23 19:35:18 2022 -0700 attempt to use cache in Nix Shell Github Action https://github.com/cachix/install-nix-action#how-do-i-add-a-binary-cache
Squashed commit of the following: commit be261f9005d7f0382bd28e384542e141d47c4c35 Author: Peter Becich <[email protected]> Date: Wed Jun 1 20:17:02 2022 -0700 Revert "test" This reverts commit 678a1ed. commit 678a1ed Author: Peter Becich <[email protected]> Date: Wed Jun 1 19:47:10 2022 -0700 test commit 7c8b2ee Author: Peter Becich <[email protected]> Date: Wed May 25 18:55:42 2022 -0700 use Cachix in GitHub Action commit b99b637 Author: Peter Becich <[email protected]> Date: Tue May 24 00:17:53 2022 -0700 attempt to fix Github Actions caching commit 49f09ed Author: Peter Becich <[email protected]> Date: Mon May 23 19:40:27 2022 -0700 attempt to cache `/nix` in Nix Shell Github Action cachix/install-nix-action#56 (comment) commit 5a5b310 Author: Peter Becich <[email protected]> Date: Mon May 23 19:35:18 2022 -0700 attempt to use cache in Nix Shell Github Action https://github.com/cachix/install-nix-action#how-do-i-add-a-binary-cache
Squashed commit of the following: commit be261f9005d7f0382bd28e384542e141d47c4c35 Author: Peter Becich <[email protected]> Date: Wed Jun 1 20:17:02 2022 -0700 Revert "test" This reverts commit 678a1ed. commit 678a1ed Author: Peter Becich <[email protected]> Date: Wed Jun 1 19:47:10 2022 -0700 test commit 7c8b2ee Author: Peter Becich <[email protected]> Date: Wed May 25 18:55:42 2022 -0700 use Cachix in GitHub Action commit b99b637 Author: Peter Becich <[email protected]> Date: Tue May 24 00:17:53 2022 -0700 attempt to fix Github Actions caching commit 49f09ed Author: Peter Becich <[email protected]> Date: Mon May 23 19:40:27 2022 -0700 attempt to cache `/nix` in Nix Shell Github Action cachix/install-nix-action#56 (comment) commit 5a5b310 Author: Peter Becich <[email protected]> Date: Mon May 23 19:35:18 2022 -0700 attempt to use cache in Nix Shell Github Action https://github.com/cachix/install-nix-action#how-do-i-add-a-binary-cache
Squashed commit of the following: commit be261f9005d7f0382bd28e384542e141d47c4c35 Author: Peter Becich <[email protected]> Date: Wed Jun 1 20:17:02 2022 -0700 Revert "test" This reverts commit 678a1ed. commit 678a1ed Author: Peter Becich <[email protected]> Date: Wed Jun 1 19:47:10 2022 -0700 test commit 7c8b2ee Author: Peter Becich <[email protected]> Date: Wed May 25 18:55:42 2022 -0700 use Cachix in GitHub Action commit b99b637 Author: Peter Becich <[email protected]> Date: Tue May 24 00:17:53 2022 -0700 attempt to fix Github Actions caching commit 49f09ed Author: Peter Becich <[email protected]> Date: Mon May 23 19:40:27 2022 -0700 attempt to cache `/nix` in Nix Shell Github Action cachix/install-nix-action#56 (comment) commit 5a5b310 Author: Peter Becich <[email protected]> Date: Mon May 23 19:35:18 2022 -0700 attempt to use cache in Nix Shell Github Action https://github.com/cachix/install-nix-action#how-do-i-add-a-binary-cache
Squashed commit of the following: commit be261f9005d7f0382bd28e384542e141d47c4c35 Author: Peter Becich <[email protected]> Date: Wed Jun 1 20:17:02 2022 -0700 Revert "test" This reverts commit 678a1ed. commit 678a1ed Author: Peter Becich <[email protected]> Date: Wed Jun 1 19:47:10 2022 -0700 test commit 7c8b2ee Author: Peter Becich <[email protected]> Date: Wed May 25 18:55:42 2022 -0700 use Cachix in GitHub Action commit b99b637 Author: Peter Becich <[email protected]> Date: Tue May 24 00:17:53 2022 -0700 attempt to fix Github Actions caching commit 49f09ed Author: Peter Becich <[email protected]> Date: Mon May 23 19:40:27 2022 -0700 attempt to cache `/nix` in Nix Shell Github Action cachix/install-nix-action#56 (comment) commit 5a5b310 Author: Peter Becich <[email protected]> Date: Mon May 23 19:35:18 2022 -0700 attempt to use cache in Nix Shell Github Action https://github.com/cachix/install-nix-action#how-do-i-add-a-binary-cache
Squashed commit of the following: commit be261f9005d7f0382bd28e384542e141d47c4c35 Author: Peter Becich <[email protected]> Date: Wed Jun 1 20:17:02 2022 -0700 Revert "test" This reverts commit 678a1ed. commit 678a1ed Author: Peter Becich <[email protected]> Date: Wed Jun 1 19:47:10 2022 -0700 test commit 7c8b2ee Author: Peter Becich <[email protected]> Date: Wed May 25 18:55:42 2022 -0700 use Cachix in GitHub Action commit b99b637 Author: Peter Becich <[email protected]> Date: Tue May 24 00:17:53 2022 -0700 attempt to fix Github Actions caching commit 49f09ed Author: Peter Becich <[email protected]> Date: Mon May 23 19:40:27 2022 -0700 attempt to cache `/nix` in Nix Shell Github Action cachix/install-nix-action#56 (comment) commit 5a5b310 Author: Peter Becich <[email protected]> Date: Mon May 23 19:35:18 2022 -0700 attempt to use cache in Nix Shell Github Action https://github.com/cachix/install-nix-action#how-do-i-add-a-binary-cache
@robinp I couldn't get your snippet to work, but had some luck with this (Edited, mentioned the wrong person): - name: Cache nix env take N+1
uses: actions/cache@v2
id: nix-cache
with:
path: |
/tmp/nix-cache
key: ${{ runner.os }}-nix-cache
- name: cache hit
if: steps.nix-cache.outputs.cache-hit == 'true'
run: |
sudo chown -R root /tmp/nix-cache
sudo cp -fRT /tmp/nix-cache/ /nix/
# cp sometimes errors out on MacOS, but rsync works.
# sudo rsync -a /tmp/nix-cache/ /nix/
sudo pkill nix-daemon
- name: do stuff
run: nix-shell --command 'echo OK'
- run: |
sudo cp -r /nix /tmp/nix-cache
# cp sometimes errors out on MacOS, but rsync works as below.
# sudo rsync -a --exclude .Trashes --exclude /var/nix/daemon-socket /nix/ /tmp/nix-cache/
sudo rm -rf /tmp/nix-cache/var/nix/daemon-socket/socket
sudo rm -rf /tmp/nix-cache/var/nix/userpool
sudo rm -rf /tmp/nix-cache/var/nix/gc.lock
sudo rm -rf /tmp/nix-cache/var/nix/db/big-lock
sudo rm -rf /tmp/nix-cache/var/nix/db/reserved Basically, I gave up on trying to cache It worked great on Linux, but was really slow on MacOS. Especially creating the intermediary copy (which is absolutely necessary on MacOS, as Tragically, it's on MacOS where I need the speed up the most, and this didn't really help too much. On Linux, for my projects, it's almost not worth the complexity. |
I wish Or this: https://docs.cachix.org/faq#is-there-a-way-to-cache-nix-shell Both seem to help only when compiling stuff. I previously discussed this with @domenkozar on cachix/cachix-action#61 , but it was a while back. I wonder if things have changed since then. |
If you want to cache the Nix store with the GitHub Actions cache, instead of trying to work around the challenges of caching the raw - name: "Cache Nix store"
uses: actions/[email protected]
id: nix-cache
with:
path: /tmp/nixcache
key: "FIXME: Pick a cache key suitable for your use case"
- name: "Install Nix"
uses: cachix/install-nix-action@v17
with:
install_url: "https://releases.nixos.org/nix/nix-2.11.0/install"
- name: "Import Nix store cache"
if: "steps.nix-cache.outputs.cache-hit == 'true'"
run: "nix-store --import < /tmp/nixcache"
- name: "Enable Cachix"
uses: cachix/cachix-action@v10
with: "FIXME: Fill in your details"
- name: "Build application"
run: "nix build --print-build-logs"
- name: "Export Nix store cache"
if: "steps.nix-cache.outputs.cache-hit != 'true'"
run: "nix-store --export $(find /nix/store -maxdepth 1 -name '*-*') > /tmp/nixcache" It works reasonably well in combination with Cachix; I’ve found that for some derivations that need to get hundreds of small-ish store paths from Cachix, it can take a few minutes to fetch them individually, while downloading from the GitHub Actions cache + importing into the Nix store together took less than a minute. The downside is that you need to watch out for what is in your |
If you use flake, you could use experimental For example, if you want to cache your
{
outputs = { nixpkgs }: with nixpkgs.legacyPackages.x86_64-linux; {
devShell.x86_64-linux = mkShell {
buildInputs = [
nodejs-16_x
];
};
};
} You could do: - name: "Cache Nix store"
uses: actions/[email protected]
id: nix-cache
with:
path: /tmp/nixcache
key: "FIXME: Pick a cache key suitable for your use case"
- name: "Install Nix"
uses: cachix/install-nix-action@v17
with:
install_url: "https://releases.nixos.org/nix/nix-2.11.0/install"
- name: "Import Nix store cache"
if: "steps.nix-cache.outputs.cache-hit == 'true'"
run: "nix copy --from /tmp/nixcache ./#devShell.x86_64-linux"
- name: "Enable Cachix"
uses: cachix/cachix-action@v10
with: "FIXME: Fill in your details"
- name: "Build application"
run: "nix build --print-build-logs"
- name: "Export Nix store cache"
if: "steps.nix-cache.outputs.cache-hit != 'true'"
run: "nix copy --to /tmp/nixcache ./#devShell.x86_64-linux" |
Caching /nix/store directly worked for me in https://github.com/nix-community/cache-nix-action |
Anybody has something equivalent for Gitlab CI ? |
Hi!
Sorry if this is a stupid question, I am new to using GitHub Actions.
I would like to cache
/nix/store
between builds to speed up the setup. Is it as easy as following this:https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#caching-dependencies
or are there any caveats or pitfalls I should take into account?
The text was updated successfully, but these errors were encountered: