forked from oxalica/rust-overlay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
172 lines (150 loc) · 8.61 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
{
description = ''
Pure and reproducible overlay for binary distributed rust toolchains.
A compatible but better replacement for rust overlay of github:mozilla/nixpkgs-mozilla.
'';
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }: let
inherit (nixpkgs.lib)
elem filterAttrs head mapAttrs mapAttrs' optionalAttrs replaceStrings warnIf;
inherit (builtins)
nixVersion compareVersions;
overlay = import ./.;
allSystems = [
"aarch64-darwin"
"aarch64-linux"
"armv5tel-linux"
"armv6l-linux"
"armv7a-linux"
"armv7l-linux"
"i686-linux"
# "mipsel-linux" # Missing `busybox`.
"powerpc64le-linux"
"riscv64-linux"
"x86_64-darwin"
"x86_64-linux"
];
in {
overlays = {
default = overlay;
rust-overlay = overlay;
};
# Compatible fields.
# Put them outside `eachSystem` to suppress duplicated warnings.
overlay =
warnIf (compareVersions nixVersion "2.7" >= 0)
"rust-overlay's flake output `overlay` is deprecated in favor of `overlays.default` for Nix >= 2.7"
overlay;
defaultPackage =
warnIf (compareVersions nixVersion "2.7" >= 0)
"rust-overlay's flake output `defaultPackage.<system>` is deprecated in favor of `packages.<system>.default` for Nix >= 2.7"
(mapAttrs (_: pkgs: pkgs.default) self.packages);
} // flake-utils.lib.eachSystem allSystems (system: let
pkgs = import nixpkgs { inherit system; overlays = [ overlay ]; };
in {
# TODO: Flake outputs except `overlay[s]` are not stabilized yet.
packages = let
select = version: comps: if version == "latest" then null else comps.default or null;
result =
mapAttrs' (version: comps: {
name = "rust_${replaceStrings ["."] ["_"] version}";
value = select version comps;
}) pkgs.rust-bin.stable //
mapAttrs' (version: comps: {
name = "rust-nightly_${version}";
value = select version comps;
}) pkgs.rust-bin.nightly //
mapAttrs' (version: comps: {
name = "rust-beta_${version}";
value = select version comps;
}) pkgs.rust-bin.beta //
rec {
rust = pkgs.rust-bin.stable.latest.default;
rust-beta = pkgs.rust-bin.beta.latest.default;
rust-nightly = pkgs.rust-bin.nightly.latest.default;
default = rust;
};
in filterAttrs (name: drv: drv != null) result;
checks = let
inherit (pkgs) rust-bin rustChannelOf;
inherit (pkgs.rust-bin) fromRustupToolchain fromRustupToolchainFile stable beta nightly;
rustHostPlatform = pkgs.rust.toRustTarget pkgs.hostPlatform;
assertEq = (flake-utils.lib.check-utils system).isEqual;
assertUrl = drv: url: assertEq (head drv.src.urls) url;
in
# Check only tier 1 targets.
optionalAttrs (elem system [ "aarch64-linux" "x86_64-linux" ]) {
url-no-arch = assertUrl stable."1.48.0".rust-src "https://static.rust-lang.org/dist/2020-11-19/rust-src-1.48.0.tar.xz";
url-kind-nightly = assertUrl nightly."2021-01-01".rustc "https://static.rust-lang.org/dist/2021-01-01/rustc-nightly-${rustHostPlatform}.tar.xz";
url-kind-beta = assertUrl beta."2021-01-01".rustc "https://static.rust-lang.org/dist/2021-01-01/rustc-beta-${rustHostPlatform}.tar.xz";
name-stable = assertEq stable."1.48.0".rustc.name "rustc-1.48.0-${rustHostPlatform}";
name-beta = assertEq beta."2021-01-01".rustc.name "rustc-1.50.0-beta.2-2021-01-01-${rustHostPlatform}";
name-nightly = assertEq nightly."2021-01-01".rustc.name "rustc-1.51.0-nightly-2021-01-01-${rustHostPlatform}";
name-stable-profile-default = assertEq stable."1.51.0".default.name "rust-default-1.51.0";
name-stable-profile-minimal = assertEq stable."1.51.0".minimal.name "rust-minimal-1.51.0";
url-kind-2 = assertUrl stable."1.48.0".cargo "https://static.rust-lang.org/dist/2020-11-19/cargo-1.48.0-${rustHostPlatform}.tar.xz";
url-kind-0 = assertUrl stable."1.47.0".cargo "https://static.rust-lang.org/dist/2020-10-08/cargo-0.48.0-${rustHostPlatform}.tar.xz";
url-kind-1 = assertUrl stable."1.34.2".llvm-tools-preview "https://static.rust-lang.org/dist/2019-05-14/llvm-tools-1.34.2%20(6c2484dc3%202019-05-13)-${rustHostPlatform}.tar.xz";
url-fix = assertUrl nightly."2019-01-10".rustc "https://static.rust-lang.org/dist/2019-01-10/rustc-nightly-${rustHostPlatform}.tar.xz";
# 1.30.0 has `rustfmt` still in preview state.
rename-unavailable = assertEq (stable."1.30.0" ? rustfmt) false;
rename-available = assertEq stable."1.48.0".rustfmt stable."1.48.0".rustfmt-preview;
latest-stable-legacy = assertEq pkgs.latest.rustChannels.stable.rustc stable.latest.rustc;
latest-beta-legacy = assertEq pkgs.latest.rustChannels.beta.rustc beta.latest.rustc;
latest-nightly-legacy = assertEq pkgs.latest.rustChannels.nightly.rustc nightly.latest.rustc;
rust-channel-of-stable = assertEq (rustChannelOf { channel = "stable"; }).rustc stable.latest.rustc;
rust-channel-of-beta = assertEq (rustChannelOf { channel = "beta"; }).rustc beta.latest.rustc;
rust-channel-of-nightly = assertEq (rustChannelOf { channel = "nightly"; }).rustc nightly.latest.rustc;
rust-channel-of-version = assertEq (rustChannelOf { channel = "1.48.0"; }).rustc stable."1.48.0".rustc;
rust-channel-of-nightly-date = assertEq (rustChannelOf { channel = "nightly"; date = "2021-01-01"; }).rustc nightly."2021-01-01".rustc;
rust-channel-of-beta-date = assertEq (rustChannelOf { channel = "beta"; date = "2021-01-01"; }).rustc beta."2021-01-01".rustc;
rustup-toolchain-stable = assertEq (fromRustupToolchain { channel = "stable"; }) stable.latest.default;
rustup-toolchain-beta = assertEq (fromRustupToolchain { channel = "beta"; }) beta.latest.default;
# rustup-toolchain-nightly = assertEq (fromRustupToolchain { channel = "nightly"; }) nightly.latest.default; # Not always available
rustup-toolchain-version = assertEq (fromRustupToolchain { channel = "1.51.0"; }) stable."1.51.0".default;
rustup-toolchain-nightly-date = assertEq (fromRustupToolchain { channel = "nightly-2021-01-01"; }) nightly."2021-01-01".default;
rustup-toolchain-beta-date = assertEq (fromRustupToolchain { channel = "beta-2021-01-01"; }) beta."2021-01-01".default;
rustup-toolchain-customization = assertEq
(fromRustupToolchain {
channel = "1.51.0";
components = [ "rustfmt" "rustc-dev" ];
targets = [ "wasm32-unknown-unknown" "aarch64-unknown-linux-gnu" ];
})
(stable."1.51.0".default.override {
extensions = [ "rustfmt" "rustc-dev" ];
targets = [ "wasm32-unknown-unknown" "aarch64-unknown-linux-gnu" ];
});
rustup-toolchain-profile-missing = assertEq (builtins.tryEval (fromRustupToolchain { channel = "1.51.0"; profile = "non_existent"; })).success false;
rustup-toolchain-profile-too-early = assertEq (builtins.tryEval (fromRustupToolchain { channel = "1.29.0"; profile = "minimal"; })).success false;
rustup-toolchain-profile-fallback = assertEq (fromRustupToolchain { channel = "1.29.0"; }) stable."1.29.0".rust;
rustup-toolchain-file-toml = assertEq
(fromRustupToolchainFile ./tests/rust-toolchain-toml)
(nightly."2021-03-25".default.override {
extensions = [ "rustfmt" "rustc-dev" ];
targets = [ "wasm32-unknown-unknown" "aarch64-unknown-linux-gnu" ];
});
rustup-toolchain-file-legacy = assertEq
(fromRustupToolchainFile ./tests/rust-toolchain-legacy)
nightly."2021-03-25".default;
rustup-toolchain-file-minimal = assertEq
(fromRustupToolchainFile ./tests/rust-toolchain-minimal)
(nightly."2021-03-25".minimal.override {
extensions = [ "rustfmt" "rustc-dev" ];
targets = [ "aarch64-unknown-linux-gnu" ];
});
latest-nightly-default = rust-bin.selectLatestNightlyWith (toolchain: toolchain.default);
# Darwin specific tests.
} // optionalAttrs (system == "aarch64-darwin") {
url-forward = assertUrl
nightly."2022-02-02".rust-docs
"https://static.rust-lang.org/dist/2022-02-02/rust-docs-nightly-x86_64-apple-darwin.tar.xz";
aarch64-darwin-use-x86-docs = rust-bin.stable."1.51.0".default.override {
targets = [ "x86_64-apple-darwin" ];
targetExtensions = [ "rust-docs" ];
};
};
});
}