Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: attribute 'overrideAttrs' missing (fetchCrate) #20

Open
colinxs opened this issue Mar 23, 2021 · 2 comments
Open

error: attribute 'overrideAttrs' missing (fetchCrate) #20

colinxs opened this issue Mar 23, 2021 · 2 comments

Comments

@colinxs
Copy link

colinxs commented Mar 23, 2021

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)?

@Mic92
Copy link
Contributor

Mic92 commented Mar 23, 2021

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.

@colinxs
Copy link
Author

colinxs commented Mar 23, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants