Correct way of wrapping packages + how to overrideAttrs of such package

Is there any best practice recommendation for wrapping Nix packages which allows easy overriding of attributes like version and hash (for example for purpose of building package in different version) ?

Let’s take QGIS package as an example.

default.nix is calling callPackage ./unwrapped.nix which builds unwrapped package which is then wrapped in postBuild step.
This approach looks quite elegant, but if I want to override version using

qgis.overrideAttrs (oldAttrs: {
  version = "xyz";
      src = fetchFromGitHub {
      owner = "qgis";
      repo = "QGIS";
      rev = "final-${lib.replaceStrings [ "." ] [ "_" ] version}";
      sha256 = "xxx";

it wouldn’t work, I guess because what really needs to be overridden is qgis-unwrapped which doesn’t look very easy job to do.

Based on this example, is there any better way how to write such derivation ?

Thank you very much.

The -unwrapped variant should also be exposed at the arg/nixpkgs level, instead of through a let definition. In general I think let definitions are a bit of an antipattern for packages, they don’t override well.

See e.g. firefox-unwrapped - you probably never want to use the package that way, but it allows overriding it. To be fair, I think most packages used this way should not actually show up in search results - firefox is a bit of an exception.

Alternatively, use the fancy new function arg to mkDerivation, which will allow users to use the values you actually passed in: Nixpkgs 22.05 manual

Still a bit awkward for buildInputs & co, because you somehow need to find the correct one to override, but at least it’s possible.

@TLATER , thank you very much for replying.

I tried to search in nixpkgs/pkgs/top-level/all-packages.nix file for unwrapped string and found that there are really very many different ways how people wrap packages.

I looked on Firefox package, but it is too complex for using it as some kind of template approach. Is there any other (more simple) package which you would recommend to use as a good example ?

Thank you very much.