How do you override the commit rev used by a Rust package?

I’m trying to install wpaperd using a newer commit from GitHub, and from the source it appears to use buildRustPackage, which may be why my override isn’t accessing the right values.

I tried to use a nixpkgs overlay, since it has worked for previous packages:

nixpkgs.overlays = [
  (final: prev: {
    wpaperd = prev.wpaperd.overrideAttrs (old: {
      src = prev.fetchFromGitHub {
        owner = "danyspin97";
        repo = "wpaperd";
        rev = "b4d956821c6b365adeb5bb4fd0d555a3bb90193d";
        hash = "sha256-AE2h6kkpeDlL9u7MODTbgot9gwH9VwUl884xca7Rx8w=";
      };
    });
  })
];

But nothing happens, no error and no updated package. Apparently from what I’m reading, this doesn’t work for Rust packages. How can I properly override the src in this case?

I believe overrideAttrs takes the new attrs, not a function.

@nairou I just did a sanity check here, and your code appears to be “correct” in that it does override the src attribute. But it will not compile due to how buildRustPackage works, not until we get this: rustPlatform.buildRustPackage: support `finalAttrs` style by amesgen · Pull Request #194475 · NixOS/nixpkgs · GitHub.

Also, I don’t exactly understand what you are trying to achieve here by mixing the derivation for wpaperd with the source for eww?

You’re thinking of .override, .overrideAttrs takes a function.

1 Like

Woops, bad copy-paste. I had an old eww override that I used as a template for this one, which didn’t work.

Does this mean that there is no way to override the source for any package that uses buildRustPackage?

I assume there is a worst-case option where I replace the wpaperd derivation entirely with a custom one, pointed at a different commit. But I don’t know how to reference that locally.

I think the least invasive temporary fix (if you don’t want to copy over the full nix expression for the package), is to apply buildRustPackage: add overrideRust attribute by 9999years · Pull Request #288430 · NixOS/nixpkgs · GitHub to your nixpkgs instance, which then let’s you override rust derivations.

2 Likes

I had the same problem and used this solution:

that would make your code something like:

nixpkgs.overlays = [
  (final: prev: {
    wpaperd = prev.wpaperd.overrideAttrs (old: rec {
      src = prev.fetchFromGitHub {
        owner = "danyspin97";
        repo = "wpaperd";
        rev = "b4d956821c6b365adeb5bb4fd0d555a3bb90193d";
        hash = "sha256-AE2h6kkpeDlL9u7MODTbgot9gwH9VwUl884xca7Rx8w=";
      };
      cargoDeps = old.cargoDeps.overrideAttrs {
        inherit src;
        outputHash = lib.fakeHash;
      };
    });
  })
];

That looks like it should work, but it again does nothing when I rebuild. “No version or selection state changes.”

I’m doing all of this within Home Manager (installed as a module), which is the only other factor that might be an issue, but I’ve used overlays on other packages within Home Manager before and had no issue.

This is the latest version I’m trying, which gets imported by home.nix:

wpaperd.nix

{ pkgs, lib, ... }: {
  nixpkgs.overlays = [
    (final: prev: {
      wpaperd = prev.wpaperd.overrideAttrs (old: rec {
        src = prev.fetchFromGitHub {
          owner = "danyspin97";
          repo = "wpaperd";
          rev = "b4d956821c6b365adeb5bb4fd0d555a3bb90193d";
          hash = "sha256-AE2h6kkpeDlL9u7MODTbgot9gwH9VwUl884xca7Rx8w=";
        };
        cargoDeps = old.cargoDeps.overrideAttrs {
          inherit src;
          outputHash = lib.fakeHash;
        };
      });
    })
  ];

  home.packages = [ pkgs.wpaperd ];
}