crate2nix icon indicating copy to clipboard operation
crate2nix copied to clipboard

How to use nightly channel

Open PuffyWithEyes opened this issue 1 year ago • 2 comments

I have default.nix which compiles the application. I have my own crate that uses several functions from nightly. My default.nix:

{ pkgs ? import ./nix/nixpkgs.nix { config = { allowUnfree = true; }; }
, lib ? pkgs.lib
, stdenv ? pkgs.stdenv
, generatedCargoNix ? import ./Cargo.nix
}:
let
  llvmclang = pkgs.llvmPackages_latest.libclang;

  generatedBuild = pkgs.callPackage generatedCargoNix {
    defaultCrateOverrides = pkgs.defaultCrateOverrides // {
      v4l2-sys-mit = attrs: {
        buildINputs = with pkgs; [
          clang
          glibc.dev
          llvmclang
          linuxHeaders
          libv4l.dev
        ];
        LIBCLANG_PATH = "${llvmclang.lib}/lib";
        BINDGEN_EXTRA_CLANG_ARGS = "-I${pkgs.linuxHeaders}/include -I${pkgs.glibc.dev}/include";
      };
      my-crate = attrs: {
        buildInputs = with pkgs; [
          clang
          cudaPackages.cuda_cudart
          cudaPackages.cuda_nvcc
          cudaPackages.libcufft
        ];
        CFLAGS = "-I${pkgs.cudaPackages.cuda_cudart}/include";
        CXXFLAGS = "-I${pkgs.cudaPackages.cuda_cudart}/include";
        CUDA_HOST_COMPILER = "${pkgs.clang}/bin/clang";
        CXX = "clang";
      };
    };
  };
in
generatedBuild.rootCrate.build

But i got an error image

PuffyWithEyes avatar Jan 03 '25 21:01 PuffyWithEyes

You should be able to generate Cargo.nix with the normal nixpkgs rustc. Then when calling it, you override buildRustCrateForPkgs. I have an example here: https://github.com/apoelstra/local-nix-ci/blob/main/andrew-utils.nix#L527-L573 though this also does several other things which might not be interesting to you.

apoelstra avatar Jan 03 '25 23:01 apoelstra

@apoelstra I'm very sorry, but I couldn't implement your example in my code. Could you send another example or explain this one in more detail, please?

PuffyWithEyes avatar Jan 06 '25 09:01 PuffyWithEyes