How to override `buildFeatures` in Rust package

I am trying to enable the experimental lessopen feature in bat in an overlay, but nothing I try works and I cannot find any information anywhere on what else to try.

I have tried:

final: prev: {
  bat = prev.bat.overrideAttrs (oldAttrs: {
    buildFeatures = (oldAttrs.buildFeatures or [ ]) ++ [ "lessopen" ];
  }
}

and

final: prev: {
  bat = prev.bat.overrideAttrs (oldAttrs: {
    cargoDeps = oldAttrs.cargoDeps.overrideAttrs (_: {
      buildFeatures = (oldAttrs.buildFeatures or [ ]) ++ [ "lessopen" ];
  });
}

but it does not seem to change anything.

When I try invalidating the hash like this:

final: prev: {
  bat = prev.bat.overrideAttrs (oldAttrs: {
    cargoDeps = oldAttrs.cargoDeps.overrideAttrs (_: {
      buildFeatures = (oldAttrs.buildFeatures or [ ]) ++ [ "lessopen" ];
      outputHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
    });
  });
}

I just get the same hash as the vanilla bat package.

After messing around with it on and off and finally discovering this post that pointed me towards looking at the source code for buildRustPackage, I discovered that the attribute I needed to override was cargoBuildFeatures, not buildFeatures.

I was able to enable bat’s lessopen feature with this:

final: prev: {
  bat = prev.bat.overrideAttrs (oldAttrs: {
    cargoBuildFeatures = (oldAttrs.cargoBuildFeatures or [ ]) ++ [ "lessopen" ];
  });
}
2 Likes