@@ -50,7 +50,7 @@ $ cargo --version
50
50
cargo 1.49.0 (d00d64df9 2020-12-05)
51
51
```
52
52
53
- ### Example : NixOS Configuration
53
+ ### Flake example : NixOS Configuration
54
54
55
55
Here's an example of using it in nixos configuration.
56
56
``` nix
@@ -79,7 +79,7 @@ Here's an example of using it in nixos configuration.
79
79
}
80
80
```
81
81
82
- ### Example : Using ` devShell ` and ` nix develop `
82
+ ### Flake example : Using ` devShell ` and ` nix develop `
83
83
84
84
Running ` nix develop ` will create a shell with the default nightly Rust toolchain installed:
85
85
@@ -95,20 +95,21 @@ Running `nix develop` will create a shell with the default nightly Rust toolchai
95
95
96
96
outputs = { self, nixpkgs, rust-overlay, flake-utils, ... }:
97
97
flake-utils.lib.eachDefaultSystem (system:
98
- let
98
+ let
99
99
overlays = [ (import rust-overlay) ];
100
100
pkgs = import nixpkgs {
101
101
inherit system overlays;
102
102
};
103
103
in
104
+ with pkgs;
104
105
{
105
- devShell = pkgs. mkShell {
106
+ devShell = mkShell {
106
107
buildInputs = [
107
- pkgs. openssl
108
- pkgs. pkgconfig
109
- pkgs. exa
110
- pkgs. fd
111
- pkgs. rust-bin.nightly.latest.default
108
+ openssl
109
+ pkgconfig
110
+ exa
111
+ fd
112
+ rust-bin.nightly.latest.default
112
113
];
113
114
114
115
shellHook = ''
@@ -122,7 +123,85 @@ Running `nix develop` will create a shell with the default nightly Rust toolchai
122
123
123
124
```
124
125
125
- ## Attributes provided by the overlay
126
+ ## Usage Examples
127
+
128
+ - Latest stable or beta rust profile.
129
+
130
+ ``` nix
131
+ rust-bin.stable.latest.default # Stable rust, default profile. If not sure, always choose this.
132
+ rust-bin.beta.latest.default # Wanna test beta compiler.
133
+ rust-bin.stable.latest.minimal # I don't need anything other than rustc, cargo, rust-std. Bye rustfmt, clippy, etc.
134
+ rust-bin.beta.latest.minimal
135
+ ```
136
+
137
+ It provices the same components as which installed by ` rustup install ` 's ` default ` or ` minimal ` profiles.
138
+
139
+ Almost always, ` default ` is what you want for development.
140
+
141
+ * Note: For difference between ` default ` and ` minimal ` profiles, see
142
+ [ rustup - Profiles] [ rust-profiles ] *
143
+
144
+ - Latest stable or beta rust profile, ** with extra components or target support** .
145
+
146
+ ``` nix
147
+ rust-bin.stable.latest.default.override {
148
+ extensions = [ "rust-src" ];
149
+ targets = [ "arm-unknown-linux-gnueabihf" ];
150
+ }
151
+ ```
152
+
153
+ - Latest ** nightly** rust profile.
154
+
155
+ ``` nix
156
+ rust-bin.selectLatestNightlyWith (toolchain: toolchain.default) # or `toolchain.minimal`
157
+ ```
158
+
159
+ * Note: Don't use ` rust-bin.nightly.latest ` . Your build would fail when some components missing on some days.
160
+ Always use ` selectLatestNightlyWith ` instead.*
161
+
162
+ - Latest ** nightly** rust profile, ** with extra components or target support** .
163
+
164
+ ``` nix
165
+ rust-bin.selectLatestNightlyWith (toolchain: toolchain.default.override {
166
+ extensions = [ "rust-src" ];
167
+ targets = [ "arm-unknown-linux-gnueabihf" ];
168
+ })
169
+ ```
170
+
171
+ - A specific version of rust:
172
+ ``` nix
173
+ rust-bin.stable."1.48.0".default
174
+ rust-bin.beta."2021-01-01".default
175
+ rust-bin.nightly."2020-12-31".default
176
+ ```
177
+
178
+ * Note: All of them are ` override ` -able like examples above.*
179
+
180
+ - If you already have a [ ` rust-toolchain ` file for rustup] [ rust-toolchain ] ,
181
+ you can simply use ` fromRustupToolchainFile ` to get the customized toolchain derivation.
182
+
183
+ ``` nix
184
+ rust-bin.fromRustupToolchainFile ./rust-toolchain
185
+ ```
186
+
187
+ - Toolchain with specific rustc git revision.
188
+
189
+ ** Warning: This may not always work (including the example below) since upstream CI periodly purges old artifacts.**
190
+
191
+ This is useful for development of rust components like [ MIRI] [ miri ] , which requires a specific revision of rust.
192
+ ``` nix
193
+ rust-bin.fromRustcRev {
194
+ rev = "a2cd91ceb0f156cb442d75e12dc77c3d064cdde4";
195
+ components = {
196
+ rustc = "sha256-x+OkPVStX00AiC3GupIdGzWluIK1BnI4ZCBbg72+ZuI=";
197
+ rust-src = "sha256-13PpzzYtd769Xkb0QzHpNfYCOnLMWFolc9QyYq98z2k=";
198
+ };
199
+ }
200
+ ```
201
+
202
+ - There also an cross-compilation example in [ ` examples/cross-aarch64 ` ] .
203
+
204
+ ## Reference: All attributes provided by the overlay
126
205
127
206
``` nix
128
207
{
@@ -144,11 +223,10 @@ Running `nix develop` will create a shell with the default nightly Rust toolchai
144
223
# with all `default` components (rustc, cargo, rustfmt, ...) available.
145
224
selectLatestNightlyWith = selector: «derivation»;
146
225
147
- # [Experimental]
148
226
# Custom toolchain from a specific rustc git revision.
149
227
# This does almost the same thing as `rustup-toolchain-install-master`. (https://crates.io/crates/rustup-toolchain-install-master)
150
228
# Parameter `components` should be an attrset with component name as key and its SRI hash as value.
151
- fromRustcRev = { pname ? .. , rev, components, target ? .. }: «derivation»;
229
+ fromRustcRev = { pname ? … , rev, components, target ? … }: «derivation»;
152
230
153
231
stable = {
154
232
# The latest stable toolchain.
@@ -206,64 +284,10 @@ Running `nix develop` will create a shell with the default nightly Rust toolchai
206
284
}
207
285
```
208
286
209
- Some examples (assume ` nixpkgs ` had the overlay applied):
210
-
211
- - Latest stable/beta/nightly rust with almost all components (provided the same as ` mozilla-overlay ` ):
212
- ` nixpkgs.rust-bin.{stable,beta,nightly}.latest.rust `
213
- - Latest stable/beta/nightly rust with ` default ` or ` minimal ` profile (provided the same as default behavior of ` rustup install ` ).
214
- ` nixpkgs.rust-bin.{stable,beta,nightly}.latest.{default,minimal} `
215
-
216
- Note: Directly using ` nightly.latest.* ` is not recommended since your build will fail when
217
- some components missing on some days. Use ` selectLatestNightlyWith ` instead, see example below.
218
-
219
- - A specific version of stable rust:
220
- ` nixpkgs.rust-bin.stable."1.48.0".default `
221
- - A specific date of beta rust:
222
- ` nixpkgs.rust-bin.beta."2021-01-01".default `
223
- - A specific date of nightly rust:
224
- ` nixpkgs.rust-bin.nightly."2020-12-31".default `
225
- - Latest stable rust with additional component ` rust-src ` and extra target
226
- ` arm-unknown-linux-gnueabihf ` :
227
-
228
- ``` nix
229
- nixpkgs.rust-bin.stable.latest.default.override {
230
- extensions = [ "rust-src" ];
231
- targets = [ "arm-unknown-linux-gnueabihf" ];
232
- }
233
- ```
234
-
235
- - Select the latest nightly toolchain with default components and ` llvm-tools-preview ` all available.
236
- It may select toolchain earlier than ` rust-bin.nightly.latest ` due to lack of components.
237
- ``` nix
238
- rust-bin.selectLatestNightlyWith (toolchain: toolchain.default.override {
239
- extensions = [ "llvm-tools-preview" ];
240
- })
241
- ```
242
-
243
- - If you already have a [ ` rust-toolchain ` file for rustup] [ rust-toolchain ] ,
244
- you can simply use ` fromRustupToolchainFile ` to get the customized toolchain derivation.
245
-
246
- ``` nix
247
- nixpkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain
248
- ```
249
-
250
- - * \[ Experimental\] *
251
- Toolchain with specific rustc git revision.
252
- This is useful for development of rust components like [ MIRI] ( https://github.com/rust-lang/miri ) .
253
- Note: the example below may not built since upstream CI periodly removes old artifacts.
254
- ``` nix
255
- rust-bin.fromRustcRev {
256
- rev = "a2cd91ceb0f156cb442d75e12dc77c3d064cdde4";
257
- components = {
258
- rustc = "sha256-x+OkPVStX00AiC3GupIdGzWluIK1BnI4ZCBbg72+ZuI=";
259
- rust-src = "sha256-13PpzzYtd769Xkb0QzHpNfYCOnLMWFolc9QyYq98z2k=";
260
- };
261
- }
262
- ```
263
-
264
- - See more examples in directory ` examples ` .
265
-
266
287
For more details, see also the source code of ` ./rust-overlay.nix ` .
267
288
268
289
[ mozilla ] : https://github.com/mozilla/nixpkgs-mozilla
269
290
[ rust-toolchain ] : https://rust-lang.github.io/rustup/overrides.html#the-toolchain-file
291
+ [ rust-profiles ] : https://rust-lang.github.io/rustup/concepts/profiles.html
292
+ [ miri ] : https://github.com/rust-lang/miri
293
+ [ `examples/cross-aarch64` ] : https://github.com/oxalica/rust-overlay/tree/master/examples/cross-aarch64
0 commit comments