about summary refs log tree commit diff
path: root/src/tools/nix-dev-shell/x/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/nix-dev-shell/x/default.nix')
-rw-r--r--src/tools/nix-dev-shell/x/default.nix77
1 files changed, 69 insertions, 8 deletions
diff --git a/src/tools/nix-dev-shell/x/default.nix b/src/tools/nix-dev-shell/x/default.nix
index e6dfbad6f19..422c1c4a2ae 100644
--- a/src/tools/nix-dev-shell/x/default.nix
+++ b/src/tools/nix-dev-shell/x/default.nix
@@ -1,22 +1,83 @@
 {
-  pkgs ? import <nixpkgs> { },
+  pkgs,
+  lib,
+  stdenv,
+  rustc,
+  python3,
+  makeBinaryWrapper,
+  # Bootstrap
+  curl,
+  pkg-config,
+  libiconv,
+  openssl,
+  patchelf,
+  cacert,
+  zlib,
+  # LLVM Deps
+  ninja,
+  cmake,
+  glibc,
 }:
-pkgs.stdenv.mkDerivation {
-  name = "x";
+stdenv.mkDerivation (self: {
+  strictDeps = true;
+  name = "x-none";
+
+  outputs = [
+    "out"
+    "unwrapped"
+  ];
 
   src = ./x.rs;
   dontUnpack = true;
 
-  nativeBuildInputs = with pkgs; [ rustc ];
+  nativeBuildInputs = [
+    rustc
+    makeBinaryWrapper
+  ];
 
+  env.PYTHON = python3.interpreter;
   buildPhase = ''
-    PYTHON=${pkgs.lib.getExe pkgs.python3} rustc -Copt-level=3 --crate-name x $src --out-dir $out/bin
+    rustc -Copt-level=3 --crate-name x $src --out-dir $unwrapped/bin
   '';
 
-  meta = with pkgs.lib; {
+  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 = licenses.mit;
+    license = lib.licenses.mit;
     mainProgram = "x";
   };
-}
+})