Skip to content

Commit 40e2748

Browse files
committed
Tweak flake outputs and README
1 parent 4c09255 commit 40e2748

File tree

2 files changed

+113
-46
lines changed

2 files changed

+113
-46
lines changed

Diff for: README.md

+93-39
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,53 @@
11
# rust-overlay
22

33
*Pure and reproducible* overlay for binary distributed rust toolchains.
4-
A better replacement for github:mozilla/nixpkgs-mozilla
4+
A compatible but better replacement for rust overlay of [github:mozilla/nixpkgs-mozilla][mozilla].
55

6-
Hashes of toolchain components are pre-fetched (and compressed) in `manifests` directory.
7-
So there's no need to have network access during nix evaluation (but nixpkgs-mozilla does).
6+
Hashes of toolchain components are pre-fetched (and compressed) in tree (`manifests` directory),
7+
so the evaluation is *pure* and no need to have network (but [nixpkgs-mozilla][mozilla] does).
8+
It also works well with [Nix Flakes](https://nixos.wiki/wiki/Flakes).
89

9-
Since the evaluation is now *pure*, it also means this can work well with [Nix Flakes](https://nixos.wiki/wiki/Flakes).
10-
11-
- [ ] Auto-updating is TODO.
10+
- The toolchain hashes are auto-updated daily using GitHub Actions.
1211
- Current oldest supported version is stable 1.29.0 and nightly 2018-09-13
1312
(which is randomly chosen).
1413

15-
## Use as classical nix overlay
16-
17-
The installaction and usage are exactly the same as nixpkgs-mozilla.
18-
You can follow https://github.com/mozilla/nixpkgs-mozilla#rust-overlay and just replace the url to
19-
https://github.com/oxalica/rust-overlay
14+
## Use as a classic Nix overlay
2015

2116
You can put the code below into your `~/.config/nixpkgs/overlays.nix`.
2217
```nix
23-
[ (import (builtins.fetchTarball https://github.com/oxalica/rust-overlay/archive/master.tar.gz)) ]
18+
[ (import (builtins.fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz")) ]
19+
```
20+
Then the provided attribute paths are available in nix command.
21+
```bash
22+
$ nix-env -iA rust-bin.stable.latest.rust # Do anything you like.
2423
```
2524

26-
Or install it into `nix-channel`:
27-
```shell
25+
Alternatively, you can install it into nix channels.
26+
```bash
2827
$ nix-channel --add https://github.com/oxalica/rust-overlay/archive/master.tar.gz rust-overlay
28+
$ nix-channel --update
2929
```
3030
And then feel free to use it anywhere like
31-
`import <nixpkgs> { overlays = [ (import <rust-overlay>) ] }` in your nix shell environment
31+
`import <nixpkgs> { overlays = [ (import <rust-overlay>) ]; }` in your nix shell environment.
3232

3333
## Use with Nix Flakes
3434

35-
This repository already has flake support. So you can simply use it as input.
36-
Here's an example of using it in nixos configuration.
35+
This repository already has flake support.
3736

37+
NOTE: **Only the output `overlay` is stable and preferred to be used in your flake.**
38+
Other outputs like `packages` and `defaultPackage` are for human try and are subject to change.
39+
40+
For a quick play, just use `nix shell` to bring the latest stable rust toolchain into scope.
41+
(All commands below requires preview version of Nix with flake support.)
42+
```shell
43+
$ nix shell github:oxalica/rust-overlay
44+
$ rustc --version
45+
rustc 1.49.0 (e1884a8e3 2020-12-29)
46+
$ cargo --version
47+
cargo 1.49.0 (d00d64df9 2020-12-05)
48+
```
49+
50+
Here's an example of using it in nixos configuration.
3851
```nix
3952
{
4053
description = "My configuration";
@@ -52,7 +65,7 @@ Here's an example of using it in nixos configuration.
5265
./configuration.nix # Your system configuration.
5366
({ pkgs, ... }: {
5467
nixpkgs.overlays = [ rust-overlay.overlay ];
55-
environment.systemPackages = [ pkgs.latest.rustChannels.stable.rust ];
68+
environment.systemPackages = [ pkgs.rust-bin.stable.latest.rust ];
5669
})
5770
];
5871
};
@@ -61,31 +74,72 @@ Here's an example of using it in nixos configuration.
6174
}
6275
```
6376

64-
## Interface
77+
## Attributes provided by the overlay
6578

66-
The overlay re-use many codes from nixpkgs/mozilla and the interface is **almost the same**.
67-
It provides `latest.rustChannels.{stable,nightly}.<toolchain-component>` and `rustChannelOf`.
79+
```nix
80+
{
81+
rust-bin = {
82+
# The default dist url for fetching.
83+
# Override it if you want to use a mirror server.
84+
distRoot = "https://static.rust-lang.org/dist";
85+
86+
stable = {
87+
# The latest stable toolchain.
88+
latest = {
89+
# Aggregate all default components. (recommended)
90+
rust = «derivation»;
91+
# Individial components.
92+
rustc = «derivation»;
93+
cargo = «derivation»;
94+
rust-std = «derivation»;
95+
# ... other components
96+
};
97+
"1.49.0" = { /* toolchain */ };
98+
"1.48.0" = { /* toolchain */ };
99+
# ... other versions.
100+
};
68101
69-
To use the latest stable or nightly rust toolchain, the easiest way is just to install
70-
`latest.rustChannels.{stable,nightly}.rust`, which combines `rustc`, `cargo`, `rustfmt` and
71-
all other default components.
102+
nightly = {
103+
# The latest nightly toolchain.
104+
latest = { /* toolchain */ };
105+
"2020-12-31" = { /* toolchain */ };
106+
"2020-12-30" = { /* toolchain */ };
107+
# ... other versions.
108+
};
72109
73-
You can also pin to specific nightly toolchain using `rustChannelOf`:
74-
```nix
75-
(nixpkgs.rustChannelOf { date = "2020-01-01"; channel = "nightly"; }).rust
76-
```
110+
# ... Some internal attributes omitted.
111+
};
77112
78-
Customize an toolchain.
79-
```nix
80-
nixpkgs.latest.rustChannels.stable.rust.override {
81-
extensions = [
82-
"rust-src"
83-
];
84-
targets = [
85-
"x86_64-unknown-linux-musl"
86-
"arm-unknown-linux-gnueabihf"
87-
];
113+
# These are for compatibility with nixpkgs-mozilla and
114+
# provide same toolchains as `rust-bin.*`.
115+
latest.rustChannels = /* ... */;
116+
rustChannelOf = /* ... */;
117+
rustChannelOfTargets = /* ... */;
118+
rustChannels = /* ... */;
88119
}
89120
```
90121

91-
For more details, see `./rust-overlay.nix` or README of https://github.com/mozilla/nixpkgs-mozilla.
122+
Some examples (assume `nixpkgs` had the overlay applied):
123+
124+
- Latest stable rust with all default components:
125+
`nixpkgs.rust-bin.stable.latest.rust`
126+
- Latest nightly rust with all default components:
127+
`nixpkgs.rust-bin.nightly.latest.rust`
128+
- A specific version of stable rust:
129+
`nixpkgs.rust-bin.stable."1.48.0".rust`
130+
- A specific date of nightly rust:
131+
`nixpkgs.rust-bin.nightly."2020-12-31".rust`
132+
- Latest stable rust with additional component `rust-src` and extra target
133+
`arm-unknown-linux-gnueabihf`:
134+
135+
```nix
136+
nixpkgs.rust-bin.stable.latest.rust.override {
137+
extensions = [ "rust-src" ];
138+
targets = [ "arm-unknown-linux-gnueabihf" ];
139+
}
140+
```
141+
142+
For detail about `override` , see the source code of `./rust-overlay.nix`,
143+
or README of [nixpkgs-mozilla][mozilla].
144+
145+
[mozilla]: https://github.com/mozilla/nixpkgs-mozilla

Diff for: flake.nix

+20-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
description = ''
33
Pure and reproducible overlay for binary distributed rust toolchains.
4-
A better replacement for github:mozilla/nixpkgs-mozilla
4+
A compatible but better replacement for rust overlay of github:mozilla/nixpkgs-mozilla.
55
'';
66

77
inputs = {
@@ -10,7 +10,8 @@
1010

1111
outputs = { self, nixpkgs, flake-utils, ... }@inputs: let
1212
inherit (nixpkgs) lib;
13-
overlay = import ./default.nix;
13+
14+
overlay = import ./.;
1415

1516
allSystems = [
1617
"aarch64-linux"
@@ -23,20 +24,32 @@
2324
];
2425

2526
in {
27+
2628
overlay = final: prev: overlay final prev;
2729

2830
} // flake-utils.lib.eachSystem allSystems (system: let
2931
pkgs = import nixpkgs { inherit system; overlays = [ overlay ]; };
3032
in rec {
33+
# `defaultApp`, `defaultPackage` and `packages` are for human only.
34+
# They are subject to change and **DO NOT** depend on them in your flake.
35+
# Please use `overlay` instead.
36+
3137
defaultApp = {
3238
type = "app";
3339
program = "${defaultPackage}/bin/rustc";
3440
};
35-
defaultPackage = packages.rust-stable;
36-
packages = {
37-
rust-stable = pkgs.latest.rustChannels.stable.rust;
38-
rust-nightly = pkgs.latest.rustChannels.nightly.rust;
39-
};
41+
defaultPackage = packages.rust;
42+
43+
# FIXME: We can only directly provide derivations here without nested set.
44+
# Currently we only provide stable releases. Some nightly versions have components missing
45+
# on some platforms, which makes `nix flake check` to be failed.
46+
packages =
47+
lib.mapAttrs' (version: comps: {
48+
name = "rust-${lib.replaceStrings ["."] ["-"] version}";
49+
value = comps.rust;
50+
}) pkgs.rust-bin.stable // {
51+
rust = packages.rust-latest;
52+
};
4053

4154
checks = {
4255
kind2 = (pkgs.rustChannelOf { channel = "1.48.0"; }).rust;

0 commit comments

Comments
 (0)