From cc3fa37d4f101c0ca7a663a09b99d52b14888f32 Mon Sep 17 00:00:00 2001 From: jcardozo-eth <131674798+jcardozo-eth@users.noreply.github.com> Date: Thu, 29 Oct 2026 12:30:02 +0100 Subject: [PATCH] fix(ci): scope the gem cache restore to the Nix environment Native gem extensions (syslog, fiddle, bigdecimal) link against the exact Nix store path of the libruby and libffi they were built with, and Ruby refuses to load an extension linked to a different libruby. The restore prefix gems-- matched any earlier bundle, so a nixpkgs bump that changed the Ruby build restored extensions compiled for the old one. require "syslog" then failed, and Puppet aborted with "Cannot determine basic system flavour". Key the cache on the dev-shell hash (the Nix files and flake.lock) and Gemfile.lock, and restore only within the same dev-shell hash. A flake change now always starts a fresh bundle; a Gemfile.lock-only change still reuses the last bundle built for the same environment. --- .github/workflows/ci.yml | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aee4af8..5a1c0d3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,13 +57,15 @@ jobs: uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: path: vendor/bundle - # Gems install under an ABI-versioned path, so a Ruby bump (a flake.lock - # change) must miss the cache; key on the Ruby series too, not just - # Gemfile.lock. restore-keys lets a Gemfile.lock change reuse the last - # good bundle for the same Ruby instead of reinstalling from scratch. - key: gems-${{ runner.os }}-${{ hashFiles('flake.lock', 'Gemfile.lock') }} + # Native gem extensions (syslog, fiddle) link against the exact Nix + # store paths of ruby and libffi, so a bundle is reusable only inside + # the same Nix environment. The key and the restore prefix both carry + # the dev-shell hash (the Nix files and flake.lock): a flake change + # always starts a fresh bundle, while a Gemfile.lock-only change still + # reuses the last bundle built for the same environment. + key: gems-${{ runner.os }}-${{ hashFiles('**/*.nix', 'flake.lock') }}-${{ hashFiles('Gemfile.lock') }} restore-keys: | - gems-${{ runner.os }}- + gems-${{ runner.os }}-${{ hashFiles('**/*.nix', 'flake.lock') }}- - name: Validate, lint, metadata, docs freshness run: >- @@ -100,13 +102,15 @@ jobs: uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: path: vendor/bundle - # Gems install under an ABI-versioned path, so a Ruby bump (a flake.lock - # change) must miss the cache; key on the Ruby series too, not just - # Gemfile.lock. restore-keys lets a Gemfile.lock change reuse the last - # good bundle for the same Ruby instead of reinstalling from scratch. - key: gems-${{ runner.os }}-${{ hashFiles('flake.lock', 'Gemfile.lock') }} + # Native gem extensions (syslog, fiddle) link against the exact Nix + # store paths of ruby and libffi, so a bundle is reusable only inside + # the same Nix environment. The key and the restore prefix both carry + # the dev-shell hash (the Nix files and flake.lock): a flake change + # always starts a fresh bundle, while a Gemfile.lock-only change still + # reuses the last bundle built for the same environment. + key: gems-${{ runner.os }}-${{ hashFiles('**/*.nix', 'flake.lock') }}-${{ hashFiles('Gemfile.lock') }} restore-keys: | - gems-${{ runner.os }}- + gems-${{ runner.os }}-${{ hashFiles('**/*.nix', 'flake.lock') }}- - name: Run unit tests run: nix develop --command sh -c 'just install && just test'