How do I patch agda for use in a nix shell?

Here’s a minimal shell.nix that I’m trying to have working:

with import <nixpkgs> { };

let
  my-agda = (agda.overrideAttrs {
    applyPatches = [ (fetchpatch { ... }) ];
  }).withPackages (p: [ p.standard-library ]);
in

mkShell {
  buildInputs = [ my-agda ];
}

this does give me agda, but not the patched one. I know because the patched behavior is not present, and there’s no build from source.

What am I missing? I’ve scoured the internet trying to make sense of it and tried so many variations of this (e.g. nixpkgs { overlays = ... }, nixpkgs { config.packageOverrides = ... }, different variants of withPackages, overrideAttrs calls, different stages on which I do each of those embellishments to the original agda packages, adding modified pname and/or version fields because I heard somewhere that they force a build from soure, etc…).

What really got my blood pressure up was that it managed to work and build once, but in haste I lost what mixture of configuration options was the successful one.

Please save my heart and possibly brain.

agda is a wrapper derivation, so patches have no effect there. You’ll need to patch the underlying haskellPackages.Agda package the derivation uses probably.

Thank you, replacing agda with haskellPackages.agda did work.

with import <nixpkgs> { };

let
  my-agda = agdaPackages.override {
    Agda = haskellPackages.Agda.overrideAttrs {
      patches = [ (fetchpatch { ... }) ];
    };
  }.agda.withPackages (p: [ p.standard-library ]);
in

mkShell {
  buildInputs = [ my-agda ];
}

Strange though. Could a nix package rebuild even if its source was unchanged? I remember well that I never attempted this solution before, and I remember just as well agda building from source.

Yes, any change to the build environment / instructions rebuilds the derivation. Nix can not predict whether such changes will make a difference to the build result or not.