From 5b9e350fd4a0cdea5e27bdcf08a649e95be3d020 Mon Sep 17 00:00:00 2001 From: Guillaume Bouchard Date: Thu, 5 Dec 2019 10:38:50 +0100 Subject: [PATCH 1/4] bazel: move configuration file to a proper nix store entry Easier to read and maintain --- .../tools/build-managers/bazel/default.nix | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pkgs/development/tools/build-managers/bazel/default.nix b/pkgs/development/tools/build-managers/bazel/default.nix index aef94073219..7a5ca2f90d2 100644 --- a/pkgs/development/tools/build-managers/bazel/default.nix +++ b/pkgs/development/tools/build-managers/bazel/default.nix @@ -21,6 +21,7 @@ , autoPatchelfHook , file , substituteAll +, writeTextFile }: let @@ -126,6 +127,14 @@ let ''; }; + bazelRC = writeTextFile { + name = "bazel-rc"; + text = '' + build --override_repository=${remote_java_tools.name}=${remote_java_tools} + build --distdir=${distDir} + ''; + }; + in stdenv.mkDerivation rec { pname = "bazel"; @@ -423,7 +432,7 @@ stdenv.mkDerivation rec { # override this path to a builtin one substituteInPlace \ src/main/cpp/option_processor.cc \ - --replace BAZEL_SYSTEM_BAZELRC_PATH "\"$out/etc/bazelrc\"" + --replace BAZEL_SYSTEM_BAZELRC_PATH "\"${bazelRC}\"" ''; in lib.optionalString stdenv.hostPlatform.isDarwin darwinPatches + genericPatches; @@ -477,13 +486,6 @@ stdenv.mkDerivation rec { 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 From 0cffa85d571ffa8d36acb5b643e2ecb6a039e5e9 Mon Sep 17 00:00:00 2001 From: Guillaume Bouchard Date: Thu, 5 Dec 2019 10:39:52 +0100 Subject: [PATCH 2/4] bazel: remove wrapProgram and move it to system configuration This way, custom configurations are all at the same place. Also, user may override these settings using the command line. --- pkgs/development/tools/build-managers/bazel/default.nix | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkgs/development/tools/build-managers/bazel/default.nix b/pkgs/development/tools/build-managers/bazel/default.nix index 7a5ca2f90d2..6d8eb56bdf3 100644 --- a/pkgs/development/tools/build-managers/bazel/default.nix +++ b/pkgs/development/tools/build-managers/bazel/default.nix @@ -132,6 +132,7 @@ let text = '' build --override_repository=${remote_java_tools.name}=${remote_java_tools} build --distdir=${distDir} + startup --server_javabase=${runJdk} ''; }; @@ -484,8 +485,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}" - # 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 From 1ce0375b2f76976956fe07ee344cdc861a0dca70 Mon Sep 17 00:00:00 2001 From: Guillaume Bouchard Date: Thu, 5 Dec 2019 10:40:36 +0100 Subject: [PATCH 3/4] bazel: close #70911 by conditionally loading system wide configuration Some system may setup global informations (such as bazel cache location) in /etc/bazel.bazelrc --- pkgs/development/tools/build-managers/bazel/default.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgs/development/tools/build-managers/bazel/default.nix b/pkgs/development/tools/build-managers/bazel/default.nix index 6d8eb56bdf3..2be3cac1748 100644 --- a/pkgs/development/tools/build-managers/bazel/default.nix +++ b/pkgs/development/tools/build-managers/bazel/default.nix @@ -133,6 +133,9 @@ let 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 ''; }; From 4fdea7312e8cfe13306cd8d70ee6b060dae956e3 Mon Sep 17 00:00:00 2001 From: Guillaume Bouchard Date: Thu, 5 Dec 2019 11:14:51 +0100 Subject: [PATCH 4/4] bazel: bazelRC path set by a patch In bazel source code change in the future, patch will fail and we'll detect the regression sooner. --- .../tools/build-managers/bazel/bazel_rc.patch | 13 +++++++++++++ .../tools/build-managers/bazel/default.nix | 13 +++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 pkgs/development/tools/build-managers/bazel/bazel_rc.patch diff --git a/pkgs/development/tools/build-managers/bazel/bazel_rc.patch b/pkgs/development/tools/build-managers/bazel/bazel_rc.patch new file mode 100644 index 00000000000..a599ac3ec72 --- /dev/null +++ b/pkgs/development/tools/build-managers/bazel/bazel_rc.patch @@ -0,0 +1,13 @@ +diff --git a/src/main/cpp/option_processor.cc b/src/main/cpp/option_processor.cc +index 8f8f15685f..a7ae52d1e4 100644 +--- a/src/main/cpp/option_processor.cc ++++ b/src/main/cpp/option_processor.cc +@@ -56,7 +56,7 @@ OptionProcessor::OptionProcessor( + : workspace_layout_(workspace_layout), + startup_options_(std::move(default_startup_options)), + parse_options_called_(false), +- system_bazelrc_path_(BAZEL_SYSTEM_BAZELRC_PATH) {} ++ system_bazelrc_path_("@bazelSystemBazelRCPath@") {} + + OptionProcessor::OptionProcessor( + const WorkspaceLayout* workspace_layout, diff --git a/pkgs/development/tools/build-managers/bazel/default.nix b/pkgs/development/tools/build-managers/bazel/default.nix index 2be3cac1748..e82bbb4aba1 100644 --- a/pkgs/development/tools/build-managers/bazel/default.nix +++ b/pkgs/development/tools/build-managers/bazel/default.nix @@ -171,6 +171,13 @@ stdenv.mkDerivation rec { 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; @@ -431,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 "\"${bazelRC}\"" ''; in lib.optionalString stdenv.hostPlatform.isDarwin darwinPatches + genericPatches;