magic-nix-cache-action icon indicating copy to clipboard operation
magic-nix-cache-action copied to clipboard

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

Open d-xo opened this issue 2 years ago • 2 comments

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 avatar Jul 19 '23 14:07 d-xo

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

silviogutierrez avatar Aug 15 '23 21:08 silviogutierrez

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.

h3h avatar Oct 11 '24 16:10 h3h