Skip to content
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

Option to locally cache paths downloaded from cache.nixos.org #21

Open
d-xo opened this issue Jul 19, 2023 · 2 comments
Open

Option to locally cache paths downloaded from cache.nixos.org #21

d-xo opened this issue Jul 19, 2023 · 2 comments

Comments

@d-xo
Copy link

d-xo commented Jul 19, 2023

So my understanding is that this action will not cache anything that has been fetched from cache.nixos.org? I would actually be very interested in caching these store paths locally as well since waiting for deps to download is currently a pretty large part of my CI execution time, and we only build a few small derivations locally (aside from the final build output which usually changes on each ci run anyway, and therefore does not benefit from caching).

Would you consider addnig an option that caches these paths too (perhaps in a seperate cache step keyed on the hash of the flake.lock to minimize churn)?.

@d-xo d-xo changed the title Option To Locally Cache Paths Downloaded From cache.nixos.org Option to locally cache paths downloaded from cache.nixos.org Jul 19, 2023
@silviogutierrez
Copy link

I found this action by way of Hacker News. Someone there asked if it caches nix-shell, and apparently it does.

But per this thread, and my experience, downloads are not cached. So I'd love to know: what does it cache when using nix-shell?

LIke @d-xo , I'd love an option for caching the downloads as these take a long time. Or at the very least, maybe document and show some snippets of code for how to manually cache the downloads.

Really looking forward to seeing this action evolve. Hopefully it greatly simplifies my caching. For now, I've had to stick to this:

name: "Setup"
runs:
    using: "composite"
    steps:
        - uses: cachix/install-nix-action@v15
          with:
              nix_path: nixpkgs=channel:nixos-unstable
        - name: Nix cache
          id: nix-cache
          uses: actions/cache@v3
          with:
              path: |
                  /tmp/nix-cache
              key: ${{ runner.os }}-nix-cache-${{ hashFiles('**/requirements.txt', '**/*.nix', 'patches/*.patch') }}
        - name: Restore Nix store
          if: steps.nix-cache.outputs.cache-hit == 'true'
          run: |
              sudo chown -R root /tmp/nix-cache

              sudo rm -rf /nix/store/
              sudo cp -fRT /tmp/nix-cache/var/ /nix/var/
              sudo mv /tmp/nix-cache/store/ /nix/store/
              sudo pkill nix-daemon
          shell: bash
        - name: Do stuff
          run: nix-shell --command "echo 'shell is up'"
          shell: bash
        - run: |
              sudo cp -r --preserve=timestamps /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
          if: steps.nix-cache.outputs.cache-hit != 'true'
          shell: bash

But it's very heavy handed. More usage here: https://github.com/silviogutierrez/reactivated/blob/main/.github/actions/setup/action.yaml

@h3h
Copy link

h3h commented Oct 11, 2024

I have the same question: How do I cache everything, including things from an upstream cache? I'm trying to eliminate a completely redundant download of deps from cachix.org on every CI build and am confused as to why these would not be cached by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants