Skip to content

unsafeGetAttrPos returns incorrect positions after overriding #16068

Description

@xaltsc

Describe the bug

Some packages define derivation attributes using arguments provided to them (typically when using pkgs.callPackage).

When overriding a package, nix seems unaware that, somehow, the location of attributes (or rather, their values) have changed.

This may be expected behaviour and not a bug conceptually, but is very much one practically.

For instance https://github.com/Mic92/nix-update/ uses this and guesses wrongly.

Steps To Reproduce

This, by far, not a minimal example, but it's the one I have at hand. Consider the following package, located at the file new-cef-binary.nix (which is just an update of cef-binary in nixpkgs):

{ cef-binary }:
let
  version = "149.0.4";
in
(
  if (cef-binary.version == version) then
    cef-binary
  else
    (cef-binary.override {
      inherit version;
      gitRevision = "2f1bfd8";
      chromiumVersion = "149.0.7827.156";
      srcHashes = {
        aarch64-linux = "sha256-iQmnlonux7I+2ACEtpdmlS1E4A+aNFgylRsykD+KgKA=";
        x86_64-linux = "sha256-bUNgdnXkfta/pA0c/OE20E53IFKfjxxENdS6Hc0YObI=";
      };
    })
).overrideAttrs
  (old: {
    passthru = old.passthru // {
      updateScript = ./update-cef.sh;
    };
  })

I'll call the resulting derivation pkg in the following.

builtins.unsafeGetAttrPos something pkg, where something is "version" or "src" for instance, returns the position in the original cef-binary/package.nix file in nixpkgs.

Expected behavior

As for the column and line attributes of the returned value, I have no opinion, but file should be /nix/store/XXXXXX-source/path/to/new-cef-binary.nix.

Metadata

nix-env (Nix) 2.34.7

Additional context

A hack for this issue is to simply inherit the old attributes in overrideAttrs, as in the following example:

{ cef-binary }:
let
  version = "149.0.4";
in
(
  if (cef-binary.version == version) then
    cef-binary
  else
    (cef-binary.override {
      inherit version;
      gitRevision = "2f1bfd8";
      chromiumVersion = "149.0.7827.156";
      srcHashes = {
        aarch64-linux = "sha256-iQmnlonux7I+2ACEtpdmlS1E4A+aNFgylRsykD+KgKA=";
        x86_64-linux = "sha256-bUNgdnXkfta/pA0c/OE20E53IFKfjxxENdS6Hc0YObI=";
      };
    })
).overrideAttrs
  (old: {
    # make nix understand that src and version are defined in this file
    inherit (old) src version;

    passthru = old.passthru // {
      updateScript = ./update-cef.sh;
    };
  })

Checklist


Add 👍 to issues you find important.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions