Skip to content

Commit aecb144

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

File tree

4 files changed

+61
-49
lines changed

4 files changed

+61
-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

+34-17
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,35 @@
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.binutils
13+
p.cmake
14+
p.ninja
15+
p.pkg-config
16+
p.python3
17+
p.git
18+
p.curl
19+
p.cacert
20+
p.patchelf
21+
p.nix
22+
p.openssl.dev
23+
p.glibc.out
24+
p.glibc.static
25+
x
26+
];
27+
28+
env = {
29+
# Avoid creating text files for ICEs.
30+
RUSTC_ICE = 0;
31+
# Provide `libstdc++.so.6` for the self-contained lld.
32+
# Provide `libz.so.1`
33+
LD_LIBRARY_PATH = let p = pkgs; in p.lib.makeLibraryPath [p.stdenv.cc.cc.lib p.zlib];
34+
};
35+
}

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

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
{
2-
pkgs ? import <nixpkgs> { },
2+
pkgs,
3+
lib,
4+
stdenv,
5+
rustc,
6+
python3,
37
}:
4-
pkgs.stdenv.mkDerivation {
5-
name = "x";
8+
stdenv.mkDerivation {
9+
strictDeps = true;
10+
pname = "x";
11+
version = "none";
612

713
src = ./x.rs;
814
dontUnpack = true;
915

10-
nativeBuildInputs = with pkgs; [ rustc ];
16+
nativeBuildInputs = [rustc];
1117

18+
env.PYTHON = lib.getExe python3;
1219
buildPhase = ''
13-
PYTHON=${pkgs.lib.getExe pkgs.python3} rustc -Copt-level=3 --crate-name x $src --out-dir $out/bin
20+
rustc -Copt-level=3 --crate-name x $src --out-dir $out/bin
1421
'';
1522

16-
meta = with pkgs.lib; {
23+
meta = {
1724
description = "Helper for rust-lang/rust x.py";
1825
homepage = "https://github.com/rust-lang/rust/blob/master/src/tools/x";
19-
license = licenses.mit;
26+
license = lib.licenses.mit;
2027
mainProgram = "x";
2128
};
2229
}

0 commit comments

Comments
 (0)