nix-prefetch icon indicating copy to clipboard operation
nix-prefetch copied to clipboard

error: attribute 'overrideAttrs' missing (fetchCrate)

Open colinxs opened this issue 3 years ago • 2 comments

Given the following rust package definition:

# This works:
{ lib, fetchzip, rustPlatform }:
rustPlatform.buildRustPackage rec {
  pname = "lscolors";
  version = "0.7.1";
  src = fetchzip {
    url = "https://crates.io/api/v1/crates/lscolors/0.7.1/download#crate.tar.gz";
    sha256 = "1kli299gg3vafjj0vbrfmwcaawq23c9dw31q25i2g3n49pyfic62";
  };
  cargoSha256 = "sha256:0dxry46dizjx7j9sdmg891dh7ji29znxdj3clcf30a27ni6ydb76";
}

# This doesn't:
# { lib, fetchCrate, rustPlatform }:
# rustPlatform.buildRustPackage rec {
#   pname = "lscolors";
#   version = "0.7.1";
#   src = fetchCrate {
#     inherit pname version;
#     sha256 = "1kli299gg3vafjj0vbrfmwcaawq23c9dw31q25i2g3n49pyfic62";
#   };
#   cargoSha256 = "sha256:0dxry46dizjx7j9sdmg891dh7ji29znxdj3clcf30a27ni6ydb76";
# }

running

nix-prefetch '{ sha256 }: (import ./default.nix {}).lscolors2.cargoDeps.overrideAttrs (_: { cargoSha256 = sha256; })'

works just fine when using fetchzip but when using fetchcrate (the commented-out block above), I get the following error:

error: attribute 'overrideAttrs' missing, at /nix/store/blqi2h6ijjanswmv20gwqx39232224ax-nix-prefetch-0.4.0/lib/nix-prefetch/prefetcher.nix:87:10

This appears to be unique to the fetchcrate fetcher. I'm guessing this is related to how fetchcrate is defined (using overrideDerivation)?

colinxs avatar Mar 23 '21 00:03 colinxs

They both seem to be derived from fetchurl but fetchcrate uses lib.overrideDerivation instead of overrideAttrs, which might cause the breakage. I don't see why we cannot switch to overrideAttrs for it as well.

Mic92 avatar Mar 23 '21 06:03 Mic92

If we're going to re-define fetchCrate then we might as well redefine it in terms of fetchzip. The following are entirely equivalent (same store paths and everything):

  lscolors_crate = fetchCrate {
    pname = "lscolors";
    version = "0.7.1";
    sha256 = "1kli299gg3vafjj0vbrfmwcaawq23c9dw31q25i2g3n49pyfic62";
  };
  lscolors_url = fetchzip {
    name = "lscolors-0.7.1";
    url = "https://crates.io/api/v1/crates/lscolors/0.7.1/download#crate.tar.gz";
    sha256 = "1kli299gg3vafjj0vbrfmwcaawq23c9dw31q25i2g3n49pyfic62";
  };

The only thing fetchCrate really needs to do is generate name and url from pname and version, everything else appears to be a duplication of what fetchzip already does.

colinxs avatar Mar 23 '21 15:03 colinxs