diff options
Diffstat (limited to 'pkgs/development/tools/build-managers/bazel/default.nix')
-rw-r--r-- | pkgs/development/tools/build-managers/bazel/default.nix | 58 |
1 files changed, 34 insertions, 24 deletions
diff --git a/pkgs/development/tools/build-managers/bazel/default.nix b/pkgs/development/tools/build-managers/bazel/default.nix index 74a4ff4a3da..e82bbb4aba1 100644 --- a/pkgs/development/tools/build-managers/bazel/default.nix +++ b/pkgs/development/tools/build-managers/bazel/default.nix @@ -19,6 +19,9 @@ , enableNixHacks ? false , gcc-unwrapped , autoPatchelfHook +, file +, substituteAll +, writeTextFile }: let @@ -91,7 +94,7 @@ let # ], # ) # - [ bash coreutils findutils gawk gnugrep gnutar gnused gzip which unzip ]; + [ bash coreutils findutils gawk gnugrep gnutar gnused gzip which unzip file zip ]; # Java toolchain used for the build and tests javaToolchain = "@bazel_tools//tools/jdk:toolchain_host${buildJdkName}"; @@ -124,6 +127,18 @@ let ''; }; + bazelRC = writeTextFile { + name = "bazel-rc"; + text = '' + build --override_repository=${remote_java_tools.name}=${remote_java_tools} + build --distdir=${distDir} + startup --server_javabase=${runJdk} + + # load default location for the system wide configuration + try-import /etc/bazel.bazelrc + ''; + }; + in stdenv.mkDerivation rec { pname = "bazel"; @@ -145,6 +160,24 @@ stdenv.mkDerivation rec { # This is breaking the build of any C target. This patch removes the last # argument if it's found to be an empty string. ./trim-last-argument-to-gcc-if-empty.patch + + # --experimental_strict_action_env (which may one day become the default + # see bazelbuild/bazel#2574) hardcodes the default + # action environment to a non hermetic value (e.g. "/usr/local/bin"). + # This is non hermetic on non-nixos systems. On NixOS, bazel cannot find the required binaries. + # So we are replacing this bazel paths by defaultShellPath, + # improving hermeticity and making it work in nixos. + (substituteAll { + src = ./strict_action_env.patch; + strictActionEnvPatch = defaultShellPath; + }) + + # bazel reads its system bazelrc in /etc + # override this path to a builtin one + (substituteAll { + src = ./bazel_rc.patch; + bazelSystemBazelRCPath = bazelRC; + }) ] ++ lib.optional enableNixHacks ./nix-hacks.patch; @@ -390,14 +423,6 @@ stdenv.mkDerivation rec { -e "/\$command \\\\$/a --host_java_toolchain='${javaToolchain}' \\\\" \ -i scripts/bootstrap/compile.sh - # --experimental_strict_action_env (which will soon become the - # default, see bazelbuild/bazel#2574) hardcodes the default - # action environment to a value that on NixOS at least is bogus. - # So we hardcode it to something useful. - substituteInPlace \ - src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java \ - --replace /bin:/usr/bin ${defaultShellPath} - # This is necessary to avoid: # "error: no visible @interface for 'NSDictionary' declares the selector # 'initWithContentsOfURL:error:'" @@ -413,12 +438,6 @@ stdenv.mkDerivation rec { mv runfiles.bash.tmp tools/bash/runfiles/runfiles.bash patchShebangs . - - # bazel reads its system bazelrc in /etc - # override this path to a builtin one - substituteInPlace \ - src/main/cpp/option_processor.cc \ - --replace BAZEL_SYSTEM_BAZELRC_PATH "\"$out/etc/bazelrc\"" ''; in lib.optionalString stdenv.hostPlatform.isDarwin darwinPatches + genericPatches; @@ -470,15 +489,6 @@ stdenv.mkDerivation rec { cp ./bazel_src/scripts/packages/bazel.sh $out/bin/bazel mv ./bazel_src/output/bazel $out/bin/bazel-real - wrapProgram "$out/bin/bazel" --add-flags --server_javabase="${runJdk}" - - # generates the system bazelrc - # warning: the name of the repository depends on the system, hence - # the reference to .name - mkdir $out/etc - echo "build --override_repository=${remote_java_tools.name}=${remote_java_tools}" > $out/etc/bazelrc - echo "build --distdir=${distDir}" >> $out/etc/bazelrc - # shell completion files mkdir -p $out/share/bash-completion/completions $out/share/zsh/site-functions mv ./bazel_src/output/bazel-complete.bash $out/share/bash-completion/completions/bazel |