Does overridden nix pkgs still cache hit?

chartdb: init at 1.19.0 by Malix-Labs · Pull Request #473469 · NixOS/nixpkgs · GitHub from @Sigmanificient :

⋯ the goal of finalAttrs is to bring full overid-ability such that i can do:

my-pkg.overrideAttrs (prev: {
  version = "new-version";
  src = fetchNewSources { ... };
})

and this alone care to change the meta.changelog which uses finalAttrs.version (for instance, this is just an example)

This made me curious about if overridden nix pkgs still cache hit?

For example: nixpkgs/pkgs/by-name/ch/chartdb/package.nix at d5b46bfdb487f89918470286c070fed9ebe17a9d · NixOS/nixpkgs · GitHub

...

buildNpmPackage (finalAttrs: {
  pname = "chartdb";
  version = "1.19.0"; # https://github.com/chartdb/chartdb/releases

  src = fetchFromGitHub {
    owner = "chartdb";
    repo = "chartdb";
    rev = "v${finalAttrs.version}";
    hash = "sha256-vRnxvX86K0Nm+h/jWN1YRJXknYsq3nBhpxRA12m9kfU=";
  };

  ...

Let’s imagine that this package’s version v1.18.0 is already cached in https://cache.nixos.org/.

Will a user overriding version to v1.18.0 (and the mandatory src fetchFromGitHub’s hash of course) hit the version cached in https://cache.nixos.org/ or will the cache miss (and thus I guess building the package from source)?
Otherwise, should a channel / nixpkgs flake input that has the specific package to v1.18.0 as its latest be pinned?

Is there any documentation about this?

Afaik, nix uses the derivation src content hash to determine whether to rebuild

1 Like

It can but I wouldn’t count on it. If a package was recently updated by changing just its src, and nothing else, then changing its src back can result in the exact same derivation that it was before, which means you’ll get a cache hit. But if anything else has changed, like any of its dependencies, the compiler, etc., then the derivation won’t be the same as the old cached one anymore and you’ll be building from source.

There is a nixpkgs branch called “staging” (or “staging-25.11” for nixos-25.11) that receives changes that are expected to change large swaths of packages in nixpkgs (often all packages). You can generally expect staging to be merged into the relevant channel every few weeks. Since staging branch merges effectively change something about all packages, this means you can’t expect this src override to remain the same derivation as the old cached one for more than a few weeks.

1 Like