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

Override compiler version #45

Closed
vbrandl opened this issue Nov 8, 2019 · 9 comments
Closed

Override compiler version #45

vbrandl opened this issue Nov 8, 2019 · 9 comments

Comments

@vbrandl
Copy link

vbrandl commented Nov 8, 2019

How can I override, which rustc version or branch (stable/beta/nightly) to use?

Also it would be cool, if crate2nix would check for rust-toolchain files which are used by rustup to pin a specific compiler version and or branch for a repository.

@kolloch
Copy link
Collaborator

kolloch commented Nov 10, 2019

You can override the rust compiler by overlays to the used nixpkgs.

I will investigate in making this easy...

@vbrandl
Copy link
Author

vbrandl commented Nov 11, 2019

Would be cool to mention this in the readme with an example.

I tried adding the mozilla overlay but I can't figure out, where do override the used compiler channel

@andir
Copy link
Collaborator

andir commented Nov 21, 2019

@vbrandl I am using the following pattern in an overlay:

self: super: {
   rustNightlyChannel = mozilla.rustChannelOf { date = "..."; channel = "..."; };
   rustNightly = self.rustNightlyChannel.rust.override { extensions = [ "rust-src" ]; };
   myBuildRustCrate = super.buildRustCrate.override { rustc = self.rustNightly; };
   myPkg = (self.callPackage ./Crate.nix { buildRustCrate = myBuildRustCrate; }).rootCrate.build;
}

(adopted from my actual, more complicated, version)

@vbrandl
Copy link
Author

vbrandl commented Nov 21, 2019

Thank you. I also found this one yesterday but I didn't come around to test it, yet: https://github.com/jD91mZM2/xidlehook/blob/master/default.nix

@cpcloud
Copy link
Contributor

cpcloud commented Nov 24, 2019

@kolloch @vbrandl Can this be closed?

@danieldk
Copy link
Contributor

danieldk commented Nov 25, 2019

This answer is similar to @andir 's, but I just wanted to make explicit that you don't need to use an overlay.buildRustCrate, which is what the file generated by crate2nix uses, allows you to specify a whole Rust toolchain through the rust argument. This can be handy when you make a package set that others should also be able to use, without defining overlays locally.

This is an example of a derivation using a nightly compiler:

https://github.com/finalfusion/nix-packages/blob/cf8a4140d2359fb512608bde3c88ba410b5d94fb/pkgs/python-modules/finalfusion/default.nix

It's self-contained, so others can use the derivation directly.

Edit: nevermind, I was still on a crate2nix branch with PR #38, and I somehow misremembered that 184d3dd made this possible.

@kolloch maybe it's still worth pursuing this approach? It's more powerful than the defaultCrateOverrides argument introduced by 184d3dd. carnix also supports overriding buildRustCrate arguments. It's more intuitive than having to override buildRustCrate first and then passing the overrided buildRustCrate as an argument.

@vbrandl
Copy link
Author

vbrandl commented Nov 25, 2019

I wasn't able to test yet because I didn't need it anymore (since 1.39.0 landed in the unstable channel, I don't need a nightly compiler for async/await). This can be closed but I think it would be nice to have a documented example in the README that shows how to use the mozilla overlay

@kolloch
Copy link
Collaborator

kolloch commented Feb 28, 2020

@andir @vbrandl @danielk I added documentation for doing this "globally" here:

https://github.com/kolloch/crate2nix#choosing-a-rust-version

I discovered one caveat: I had to use "rust" (without the c suffix) for "rustc" with a recent version of the overlay because otherwise rustc wouldn't find the std sources.

Doing this globally is often what you want, I guess. Build all your stuff with the same rust compiler. But the individual approach also has merrit. Maybe you want to add that to the documentation? You would be welcome.

@danielk for making buildRustCrate more directly overridable, see #77. Tell me what you think! For "pkgs" it is not the right tool, though, since you also want to override it for all dependencies, correct?

@kolloch
Copy link
Collaborator

kolloch commented Feb 28, 2020

I will close this issue for now but will gladly accept documentation fixes/extensions.

@kolloch kolloch closed this as completed Feb 28, 2020
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

5 participants