about summary refs log tree commit diff
path: root/src/tools/nix-dev-shell/x/default.nix
blob: 422c1c4a2aed8b164b32db62be47c0aafef4c1be (plain)
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
{
  pkgs,
  lib,
  stdenv,
  rustc,
  python3,
  makeBinaryWrapper,
  # Bootstrap
  curl,
  pkg-config,
  libiconv,
  openssl,
  patchelf,
  cacert,
  zlib,
  # LLVM Deps
  ninja,
  cmake,
  glibc,
}:
stdenv.mkDerivation (self: {
  strictDeps = true;
  name = "x-none";

  outputs = [
    "out"
    "unwrapped"
  ];

  src = ./x.rs;
  dontUnpack = true;

  nativeBuildInputs = [
    rustc
    makeBinaryWrapper
  ];

  env.PYTHON = python3.interpreter;
  buildPhase = ''
    rustc -Copt-level=3 --crate-name x $src --out-dir $unwrapped/bin
  '';

  installPhase =
    let
      inherit (self.passthru) cacert env;
    in
    ''
      makeWrapper $unwrapped/bin/x $out/bin/x \
        --set-default SSL_CERT_FILE ${cacert} \
        --prefix CPATH ";" "${lib.makeSearchPath "include" env.cpath}" \
        --prefix PATH : ${lib.makeBinPath env.path} \
        --prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath env.ldLib}
    '';

  # For accessing them in the devshell
  passthru = {
    env = {
      cpath = [ libiconv ];
      path = [
        python3
        patchelf
        curl
        pkg-config
        cmake
        ninja
        stdenv.cc
      ];
      ldLib = [
        openssl
        zlib
        stdenv.cc.cc.lib
      ];
    };
    cacert = "${cacert}/etc/ssl/certs/ca-bundle.crt";
  };

  meta = {
    description = "Helper for rust-lang/rust x.py";
    homepage = "https://github.com/rust-lang/rust/blob/master/src/tools/x";
    license = lib.licenses.mit;
    mainProgram = "x";
  };
})