@@ -1,7 +1,9 @@
1−{ stdenv, lib, fetchurl, jdk, zip, unzip, bash, writeScriptBin, coreutils, makeWrapper, which, python
1+{ stdenv, lib, fetchurl, jdk, zip, unzip, bash, writeCBin, coreutils, makeWrapper, which, python
22# Always assume all markers valid (don't redownload dependencies).
33# Also, don't clean up environment variables.
44, enableNixHacks ? false
5+# Apple dependencies
6+, libcxx, CoreFoundation, CoreServices, Foundation
57}:
68
79stdenv.mkDerivation rec {
@@ -13,7 +15,7 @@ stdenv.mkDerivation rec {
1315 description = "Build tool that builds code quickly and reliably";
1416 license = licenses.asl20;
1517 maintainers = [ maintainers.philandstuff ];
16− platforms = platforms.linux;
18+ platforms = platforms.linux ++ platforms.darwin;
1719 };
1820
1921 name = "bazel-${version}";
@@ -29,9 +31,30 @@ stdenv.mkDerivation rec {
2931
3032 # Bazel expects several utils to be available in Bash even without PATH. Hence this hack.
3133
32− customBash = writeScriptBin "bash" ''
33− #!${stdenv.shell}
34− PATH="$PATH:${lib.makeBinPath [ coreutils ]}" exec ${bash}/bin/bash "$@"
34+ customBash = writeCBin "bash" ''
35+ #include <stdio.h>
36+ #include <stdlib.h>
37+ #include <string.h>
38+ #include <unistd.h>
39+
40+ extern char **environ;
41+
42+ int main(int argc, char *argv[]) {
43+ printf("environ: %s\n", environ[0]);
44+ char *path = getenv("PATH");
45+ char *pathToAppend = "${lib.makeBinPath [ coreutils ]}";
46+ char *newPath;
47+ if (path != NULL) {
48+ int length = strlen(path) + 1 + strlen(pathToAppend) + 1;
49+ newPath = malloc(length * sizeof(char));
50+ snprintf(newPath, length, "%s:%s", path, pathToAppend);
51+ } else {
52+ newPath = pathToAppend;
53+ }
54+ setenv("PATH", newPath, 1);
55+ execve("${bash}/bin/bash", argv, environ);
56+ return 0;
57+ }
3558 '';
3659
3760 postPatch = ''
@@ -54,7 +77,7 @@ stdenv.mkDerivation rec {
5477 makeWrapper
5578 which
5679 customBash
57− ];
80+ ] ++ lib.optionals (stdenv.isDarwin) [ libcxx CoreFoundation CoreServices Foundation ];
5881
5982 # If TMPDIR is in the unpack dir we run afoul of blaze's infinite symlink
6083 # detector (see com.google.devtools.build.lib.skyframe.FileFunction).