Rust: Difference between revisions

Artturin (talk | contribs)
Installation via rustup: use bindgenHook and remove now uneccesary attrs
Artturin (talk | contribs)
Add example for how to overrideAttrs rust packages
Line 163: Line 163:


== Using overrideAttrs with Rust Packages ==
== Using overrideAttrs with Rust Packages ==
 
<syntaxhighlight lang="nix">
[https://discourse.nixos.org/t/is-it-possible-to-override-cargosha256-in-buildrustpackage/4393/7 This does not seem to be possible.]
nil = pkgs.nil.overrideAttrs (
 
  finalAttrs: previousAttrs: {
== Using overrideArgs with Rust Packages ==
    version = "unstable-2024-09-19";
 
                                                                         
This is a bit tricky, you can't just use <code>overrideArgs</code>. [https://discourse.nixos.org/t/is-it-possible-to-override-cargosha256-in-buildrustpackage/4393/3 Here] is one example of how to do it. The trick is to use two nested calls to <code>overrideAttrs</code>; the outer call overrides the <code>cargoDeps</code> attribute, the inner call rebuilds the vendored tarball and provides the updated hash:
    src = pkgs.fetchFromGitHub {
 
      owner = "oxalica";
<syntaxHighlight lang="nix">
      repo = "nil";
overlays = [
      rev = "c8e8ce72442a164d89d3fdeaae0bcc405f8c015a";
  (final: prev: {
      hash = "sha256-mIuOP4I51eFLquRaxMKx67pHmhatZrcVPjfHL98v/M8=";
     some-nixpkgs-package = prev.some-nixpkgs-package.overrideAttrs (oldAttrs: {
    };
      cargoDeps = oldAttrs.cargoDeps.overrideAttrs (_: {
                                                                         
        # ...
    # Requires IFD
      });
    cargoDeps = pkgs.rustPlatform.importCargoLock {
     });
      lockFile = finalAttrs.src + "/Cargo.lock";
   })
      allowBuiltinFetchGit = true;
];
    };
</syntaxHighlight>
    cargoHash = null;
                                                                         
    # Doesn't require IFD
     #cargoDeps = previousAttrs.cargoDeps.overrideAttrs {
    #  name = "nil-vendor.tar.gz";
    #  inherit (finalAttrs) src;
    #  #outputHash = pkgs.lib.fakeHash;
    #  outputHash = "sha256-RWgknkeGNfP2wH1X6nc+b10Qg1QX3UeewDdeWG0RIE8=";
     #};
   }
);
</syntaxhighlight>


== Packaging Rust projects with nix ==
== Packaging Rust projects with nix ==