Skip to content

Commit 103be60

Browse files
authored
Rollup merge of rust-lang#139297 - RossSmyth:NixClean, r=WaffleLapkin
Deduplicate & clean up Nix shell 1. Deduplicate the flake and shell files 2. Remove flake-utils 3. Remove `with` statements They are considered bad practice nowadays because the slow down the evalulator and have weird shadowing rules. 4. Use `env` :3 5. use `callPackage` It's the recommended way for derivations like these. 6. Use `packages` in the shell There is no reason to use `buildInputs` for a mkShell (except in funny cases that will not be seen here), so the `packages` attr is recommended now days. r? WaffleLapkin
2 parents db98b72 + 5a38550 commit 103be60

File tree

3 files changed

+111
-50
lines changed

3 files changed

+111
-50
lines changed

src/tools/nix-dev-shell/flake.nix

+19-27
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,24 @@
11
{
22
description = "rustc dev shell";
33

4-
inputs = {
5-
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6-
flake-utils.url = "github:numtide/flake-utils";
7-
};
4+
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
85

9-
outputs = { self, nixpkgs, flake-utils, ... }:
10-
flake-utils.lib.eachDefaultSystem (system:
11-
let
12-
pkgs = import nixpkgs { inherit system; };
13-
x = import ./x { inherit pkgs; };
14-
in
15-
{
16-
devShells.default = with pkgs; mkShell {
17-
name = "rustc-dev-shell";
18-
nativeBuildInputs = with pkgs; [
19-
binutils cmake ninja pkg-config python3 git curl cacert patchelf nix
20-
];
21-
buildInputs = with pkgs; [
22-
openssl glibc.out glibc.static x
23-
];
24-
# Avoid creating text files for ICEs.
25-
RUSTC_ICE = "0";
26-
# Provide `libstdc++.so.6` for the self-contained lld.
27-
# Provide `libz.so.1`.
28-
LD_LIBRARY_PATH = "${with pkgs; lib.makeLibraryPath [stdenv.cc.cc.lib zlib]}";
29-
};
30-
}
31-
);
6+
outputs =
7+
{
8+
self,
9+
nixpkgs,
10+
}:
11+
let
12+
inherit (nixpkgs) lib;
13+
forEachSystem = lib.genAttrs lib.systems.flakeExposed;
14+
in
15+
{
16+
devShells = forEachSystem (system: {
17+
default = nixpkgs.legacyPackages.${system}.callPackage ./shell.nix { };
18+
});
19+
20+
packages = forEachSystem (system: {
21+
default = nixpkgs.legacyPackages.${system}.callPackage ./x { };
22+
});
23+
};
3224
}

src/tools/nix-dev-shell/shell.nix

+23-15
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
1-
{ pkgs ? import <nixpkgs> {} }:
2-
let
3-
x = import ./x { inherit pkgs; };
1+
{
2+
pkgs ? import <nixpkgs> { },
3+
}:
4+
let
5+
inherit (pkgs.lib) lists attrsets;
6+
7+
x = pkgs.callPackage ./x { };
8+
inherit (x.passthru) cacert env;
49
in
510
pkgs.mkShell {
6-
name = "rustc";
7-
nativeBuildInputs = with pkgs; [
8-
binutils cmake ninja pkg-config python3 git curl cacert patchelf nix
9-
];
10-
buildInputs = with pkgs; [
11-
openssl glibc.out glibc.static x
12-
];
13-
# Avoid creating text files for ICEs.
14-
RUSTC_ICE = "0";
15-
# Provide `libstdc++.so.6` for the self-contained lld.
16-
# Provide `libz.so.1`
17-
LD_LIBRARY_PATH = "${with pkgs; lib.makeLibraryPath [stdenv.cc.cc.lib zlib]}";
11+
name = "rustc-shell";
12+
13+
inputsFrom = [ x ];
14+
packages = [
15+
pkgs.git
16+
pkgs.nix
17+
x
18+
# Get the runtime deps of the x wrapper
19+
] ++ lists.flatten (attrsets.attrValues env);
20+
21+
env = {
22+
# Avoid creating text files for ICEs.
23+
RUSTC_ICE = 0;
24+
SSL_CERT_FILE = cacert;
25+
};
1826
}

src/tools/nix-dev-shell/x/default.nix

+69-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,83 @@
11
{
2-
pkgs ? import <nixpkgs> { },
2+
pkgs,
3+
lib,
4+
stdenv,
5+
rustc,
6+
python3,
7+
makeBinaryWrapper,
8+
# Bootstrap
9+
curl,
10+
pkg-config,
11+
libiconv,
12+
openssl,
13+
patchelf,
14+
cacert,
15+
zlib,
16+
# LLVM Deps
17+
ninja,
18+
cmake,
19+
glibc,
320
}:
4-
pkgs.stdenv.mkDerivation {
5-
name = "x";
21+
stdenv.mkDerivation (self: {
22+
strictDeps = true;
23+
name = "x-none";
24+
25+
outputs = [
26+
"out"
27+
"unwrapped"
28+
];
629

730
src = ./x.rs;
831
dontUnpack = true;
932

10-
nativeBuildInputs = with pkgs; [ rustc ];
33+
nativeBuildInputs = [
34+
rustc
35+
makeBinaryWrapper
36+
];
1137

38+
env.PYTHON = python3.interpreter;
1239
buildPhase = ''
13-
PYTHON=${pkgs.lib.getExe pkgs.python3} rustc -Copt-level=3 --crate-name x $src --out-dir $out/bin
40+
rustc -Copt-level=3 --crate-name x $src --out-dir $unwrapped/bin
1441
'';
1542

16-
meta = with pkgs.lib; {
43+
installPhase =
44+
let
45+
inherit (self.passthru) cacert env;
46+
in
47+
''
48+
makeWrapper $unwrapped/bin/x $out/bin/x \
49+
--set-default SSL_CERT_FILE ${cacert} \
50+
--prefix CPATH ";" "${lib.makeSearchPath "include" env.cpath}" \
51+
--prefix PATH : ${lib.makeBinPath env.path} \
52+
--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath env.ldLib}
53+
'';
54+
55+
# For accessing them in the devshell
56+
passthru = {
57+
env = {
58+
cpath = [ libiconv ];
59+
path = [
60+
python3
61+
patchelf
62+
curl
63+
pkg-config
64+
cmake
65+
ninja
66+
stdenv.cc
67+
];
68+
ldLib = [
69+
openssl
70+
zlib
71+
stdenv.cc.cc.lib
72+
];
73+
};
74+
cacert = "${cacert}/etc/ssl/certs/ca-bundle.crt";
75+
};
76+
77+
meta = {
1778
description = "Helper for rust-lang/rust x.py";
1879
homepage = "https://github.com/rust-lang/rust/blob/master/src/tools/x";
19-
license = licenses.mit;
80+
license = lib.licenses.mit;
2081
mainProgram = "x";
2182
};
22-
}
83+
})

0 commit comments

Comments
 (0)