Skip to content

Commit bbc4b68

Browse files
drakon64kolloch
authored andcommitted
Document using rust-overlay
Fixes #359
1 parent f04c351 commit bbc4b68

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
title: Using a Rust overlay
3+
---
4+
5+
It's possible to use a Rust overlay such as `rust-overlay` with `crate2nix`.
6+
This can be used for pinning the Rust toolchain version, or to use a newer toolchain version than is available in Nixpkgs.
7+
8+
In a flake with flake-parts:
9+
10+
```nix
11+
# flake.nix
12+
{
13+
# ...
14+
15+
inputs = {
16+
flake-parts = {
17+
url = "github:hercules-ci/flake-parts";
18+
inputs.nixpkgs-lib.follows = "nixpkgs";
19+
};
20+
crate2nix.url = "github:nix-community/crate2nix";
21+
# ...
22+
};
23+
24+
outputs =
25+
inputs @ { self
26+
, nixpkgs
27+
, flake-parts
28+
, rust-overlay
29+
, crate2nix
30+
, ...
31+
}:
32+
flake-parts.lib.mkFlake { inherit inputs; } {
33+
systems = [
34+
"x86_64-linux"
35+
"aarch64-linux"
36+
"x86_64-linux"
37+
"aarch64-darwin"
38+
];
39+
40+
perSystem = { system, lib, inputs', ... }:
41+
let
42+
pkgs = import nixpkgs {
43+
inherit system;
44+
45+
overlays = [ rust-overlay.overlays.default ];
46+
};
47+
48+
buildRustCrateForPkgs =
49+
crate:
50+
pkgs.buildRustCrate.override {
51+
rustc = pkgs.rust-bin.stable.latest.default;
52+
cargo = pkgs.rust-bin.stable.latest.default;
53+
};
54+
55+
generatedCargoNix = inputs.crate2nix.tools.${system}.appliedCargoNix {
56+
name = "rustnix";
57+
src = ./.;
58+
};
59+
60+
cargoNix = import generatedCargoNix {
61+
inherit pkgs buildRustCrateForPkgs;
62+
};
63+
in
64+
rec {
65+
checks = {
66+
rustnix = cargoNix.rootCrate.build.override {
67+
runTests = true;
68+
};
69+
};
70+
71+
packages = {
72+
rustnix = cargoNix.rootCrate.build;
73+
default = packages.rustnix;
74+
};
75+
};
76+
};
77+
}
78+
```

docs/src/content/docs/90_reference/90_CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: A list of all major changes per version.
55

66
## 0.14.x - 0.15.0 (unreleased)
77

8-
TODO
8+
* [#359](https://github.com/nix-community/crate2nix/issues/359): Document using `rust-overlay`.
99

1010
## 0.14.x - 0.14.1 (2024-06-30)
1111

0 commit comments

Comments
 (0)