How do I access a package input properties from `overrideAttrs`?

I want to overlay/override a package, but I want to put a condition based on the package input. Is this possible?

Imagine for the following package:

{
  lib,
  stdenv,
  fetchFromGitHub,
  backend ? "default",
}:

assert backend == "default" || backend == "other";

stdenv.mkDerivation (finalAttrs: {
  pname = "some-package-${backend}";
  version = "5.1.1";

  src = fetchFromGitHub {
    ...
  };

  meta = {
    platforms =
      [ "x86_64-linux" "aarch64-linux" ] ++ lib.optionals (backend == "default") [ "x86_64-darwin" ];
  };
})

How can I use `overrideAttrs` for this package to add `"“aarch64-darwin””` to `meta.platforms` only if the package input attribute `backend` is equal to `"default”`?

1 Like

Unless you can modify the original package to make it possible, I don’t believe so. EDIT: well, you can detect the changes in results that were based on that input, like in this case checking if meta.platforms contains "x86_64-darwin".

If you can modify the original package, put backend in passthru, then you can pull it back out again in the override.

I would like to see nixpkgs add some way to access the inputs that were supplied by callPackage from the final object. There are a few niche uses for such a thing.

1 Like