Skip to content

Commit b7d05e7

Browse files
committed
Deduplicate nix code
And clean it up a little.
1 parent ae9173d commit b7d05e7

File tree

4 files changed

+75
-49
lines changed

4 files changed

+75
-49
lines changed

Diff for: result

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/nix/store/in1pq3wd1sm6ylnxy2q6aw19gb3h650r-x-none

Diff for: src/tools/nix-dev-shell/flake.nix

+12-25
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,19 @@
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-
};
6+
outputs = {
7+
self,
8+
nixpkgs,
9+
}: let
10+
inherit (nixpkgs) lib;
11+
forEachSystem = lib.genAttrs lib.systems.flakeExposed;
12+
in {
13+
devShells = forEachSystem (
14+
system: {
15+
default = nixpkgs.legacyPackages.${system}.callPackage ./shell.nix {};
3016
}
3117
);
18+
};
3219
}

Diff for: src/tools/nix-dev-shell/shell.nix

+21-17
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1-
{ pkgs ? import <nixpkgs> {} }:
2-
let
3-
x = import ./x { inherit pkgs; };
1+
{pkgs ? import <nixpkgs> {}}: let
2+
x = pkgs.callPackage ./x {};
43
in
5-
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]}";
18-
}
4+
pkgs.mkShell {
5+
strictDeps = true;
6+
pname = "rustc-shell";
7+
version = "none";
8+
9+
packages = let
10+
p = pkgs;
11+
in [
12+
p.git
13+
p.nix
14+
p.glibc
15+
x
16+
];
17+
18+
env = {
19+
# Avoid creating text files for ICEs.
20+
RUSTC_ICE = 0;
21+
};
22+
}

Diff for: src/tools/nix-dev-shell/x/default.nix

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

732
src = ./x.rs;
833
dontUnpack = true;
934

10-
nativeBuildInputs = with pkgs; [ rustc ];
35+
nativeBuildInputs = [rustc makeBinaryWrapper];
1136

37+
env.PYTHON = python3.interpreter;
1238
buildPhase = ''
13-
PYTHON=${pkgs.lib.getExe pkgs.python3} rustc -Copt-level=3 --crate-name x $src --out-dir $out/bin
39+
rustc -Copt-level=3 --crate-name x $src --out-dir $unwrapped/bin
1440
'';
1541

16-
meta = with pkgs.lib; {
42+
installPhase = ''
43+
makeWrapper $unwrapped/bin/x $out/bin/x \
44+
--set-default SSL_CERT_FILE "${cacert}/etc/ssl/certs/ca-bundle.crt" \
45+
--prefix CPATH ";" "${lib.makeSearchPath "include" [libiconv]}" \
46+
--prefix PATH : ${lib.makeBinPath [python3 patchelf curl pkg-config cmake ninja]} \
47+
--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [openssl glibc.static zlib stdenv.cc.cc.lib]}
48+
'';
49+
50+
meta = {
1751
description = "Helper for rust-lang/rust x.py";
1852
homepage = "https://github.com/rust-lang/rust/blob/master/src/tools/x";
19-
license = licenses.mit;
53+
license = lib.licenses.mit;
2054
mainProgram = "x";
2155
};
2256
}

0 commit comments

Comments
 (0)