nix-community / cache-nix-action

Cache Nix store in GitHub Actions to speed up workflows [maintainer=@deemp]
MIT License
34 stars 7 forks source link

Upgrading to 5.1.1 breaks restore #34

Closed Munksgaard closed 5 months ago

Munksgaard commented 5 months ago

I have the following step in my workflow file:

      - name: Restore and cache Nix store
        uses: nix-community/cache-nix-action@v5
        with:
          # restore and save a cache using this key
          primary-key: nix-${{ runner.os }}-${{ hashFiles('**/*.nix') }}
          # if there's no cache hit, restore a cache by this prefix
          restore-prefixes-first-match: nix-${{ runner.os }}-
          paths: |
            deps
            _build

After the release of v5.1.1, I get the following error in my CI log:

Run nix-community/cache-nix-action@v5
  with:
    primary-key: nix-Linux-a036be222bc54cc20999ae15695ecdda0db82aa259484b3ab57b0f0b78ae270a
    restore-prefixes-first-match: nix-Linux-
    paths: deps
  _build

    skip-restore-on-hit-primary-key: false
    nix: true
    save: true
    purge: false
    save-always: false
    token: ***
  env:
    REGISTRY: ghcr.io
    IMAGE_NAME: redacted/redacted
    NIX_CONFIG: experimental-features = nix-command flakes
    NIX_PROFILES: /nix/var/nix/profiles/default /home/runner/.nix-profile
    NIX_USER_PROFILE_DIR: /nix/var/nix/profiles/per-user/runner
    NIX_SSL_CERT_FILE: /etc/ssl/certs/ca-certificates.crt
    NIX_USER_CONF_FILES: /tmp/tmp.LwlP8djW0a/flake-nixConfig.conf:/home/runner/.config/nix/nix.conf:
Searching for a cache with the key "nix-Linux-a036be222bc54cc20999ae15695ecdda0db82aa259484b3ab57b0f0b78ae270a".
Could not find a cache.
Searching for a cache using the "restore-prefixes-first-match":
["nix-Linux-"]
Lookup only - skipping download
Found a cache using the "restore-prefixes-first-match".
Copying "/nix/var/nix/db/db.sqlite" to "/home/runner/work/_temp/527cec4a-6440-4da1-aa05-ef10e8248d6c/old.sqlite".
Restoring a cache with the key "nix-Linux-b4c8302b1a106303f6bedbc66ceac1efb38adee347673df88edb1b8cf2badb6f".
Logs produced while restoring a cache.
Finished restoring the cache.
Copying "/nix/var/nix/db/db.sqlite" to "/home/runner/work/_temp/527cec4a-6440-4da1-aa05-ef10e8248d6c/new.sqlite".
Merging store databases "/home/runner/work/_temp/527cec4a-6440-4da1-aa05-ef10e8248d6c/old.sqlite" and "/home/runner/work/_temp/527cec4a-6440-4da1-aa05-ef10e8248d6c/new.sqlite"
into "/nix/var/nix/db/db.sqlite".
Error: ENOENT: no such file or directory, open 'src/templates/merge.sql'

Curiously though, the step doesn't actually "fail" in the CI, so the build doesn't break until I try to use nix in a later step:

Run nix develop -c mix deps.get
  nix develop -c mix deps.get
  shell: /usr/bin/bash -e {0}
  env:
    REGISTRY: ghcr.io
    IMAGE_NAME: redacted/redacted
    NIX_CONFIG: experimental-features = nix-command flakes
    NIX_PROFILES: /nix/var/nix/profiles/default /home/runner/.nix-profile
    NIX_USER_PROFILE_DIR: /nix/var/nix/profiles/per-user/runner
    NIX_SSL_CERT_FILE: /etc/ssl/certs/ca-certificates.crt
    NIX_USER_CONF_FILES: /tmp/tmp.LwlP8djW0a/flake-nixConfig.conf:/home/runner/.config/nix/nix.conf:
error: cannot open SQLite database '/nix/var/nix/db/db.sqlite': unable to open database file
Error: Process completed with exit code 1.

Explicitly specifying that I want to use 5.1.0 in my caching step causes the issue to go away.

deemp commented 5 months ago

Yes, I should've inlined the .sql file into generated JS.

deemp commented 5 months ago

@Munksgaard, I fixed the problem with .sql in v5.1.2 (worked for me here).

I suggest to discuss another part of your issue in https://github.com/nix-community/cache-nix-action/issues/35

Munksgaard commented 5 months ago

Thanks for the quick turnaround! And yes, thanks for opening the other issue as well, that definitely weirded me out for a minute :D