Skip to content

Commit 1511224

Browse files
surmakolloch
authored andcommitted
Add docs about custom toolchains
1 parent bbc4b68 commit 1511224

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
title: Custom Toolchains
3+
---
4+
5+
One way to use a custom rust toolchain with `crate2nix` is to
6+
import nixpkgs with an overlay for `rustc`.
7+
8+
Here is an example flake using [fenix]:
9+
10+
```nix
11+
12+
{
13+
description = "containix";
14+
15+
inputs = {
16+
nixpkgs.url = "github:NixOS/nixpkgs/24.05";
17+
fenix = {
18+
url = "github:nix-community/fenix";
19+
inputs.nixpkgs.follows = "nixpkgs";
20+
};
21+
flake-utils.url = "github:numtide/flake-utils";
22+
crate2nix.url = "github:nix-community/crate2nix";
23+
};
24+
25+
outputs =
26+
{
27+
self,
28+
nixpkgs,
29+
flake-utils,
30+
fenix,
31+
crate2nix,
32+
}:
33+
flake-utils.lib.eachDefaultSystem (
34+
system:
35+
let
36+
toolchain = fenix.packages.${system}.stable.defaultToolchain;
37+
38+
pkgs = import nixpkgs {
39+
inherit system;
40+
overlays = [
41+
(final: prev: {
42+
rustc = toolchain;
43+
cargo = toolchain;
44+
})
45+
];
46+
};
47+
48+
crate2nix' = pkgs.callPackage (import "${crate2nix}/tools.nix") {};
49+
cargoNix = crate2nix.appliedCargoNix {
50+
name = "my-crate";
51+
src = ./.;
52+
};
53+
in
54+
{
55+
packages = {
56+
default = cargoNix.rootCrate.build;
57+
};
58+
}
59+
);
60+
}
61+
62+
```
63+
64+
[fenix]: https://github.com/nix-community/fenix

0 commit comments

Comments
 (0)