From ce96bc54ec76ee74b2c28eb2e1d41448d478ebc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20Li=C3=A9tar?= Date: Fri, 20 Jun 2025 23:04:38 +0100 Subject: [PATCH] gradle: fix usage of update-deps script without bwrap The gradle build hook exposes an update-deps script that can, supposedly, run without bwrap if the USE_BWRAP environment is set to 0. Unfortunately the test on the variable was checking if it had an non-empty value (using -n), but just above the variable is given a default value in cases when it is empty. This meant the variable could never be empty and therefore bwrap is always used (assuming the Nix parameter useBwrap is true). By changing the test into an inequality check against zero, we can disable bwrap by setting `USE_BWRAP=0`. Any other value will leave bwrap enabled. Unfortunately the lack of boolean values in bash make it non-obvious what the best representation and test for this should be. We could also check for equality against 1 for example, or some more complicated test that handles the string "false" as well. Using 0 as the false value seems common place enough in scripts though. The conversion of `useBwrap` to a string needs to be adjusted, as `builtins.toString` actually returns an empty string for a false value. --- pkgs/development/tools/build-managers/gradle/update-deps.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/development/tools/build-managers/gradle/update-deps.nix b/pkgs/development/tools/build-managers/gradle/update-deps.nix index 2e03f70df70c..56c18a0577a3 100644 --- a/pkgs/development/tools/build-managers/gradle/update-deps.nix +++ b/pkgs/development/tools/build-managers/gradle/update-deps.nix @@ -129,8 +129,8 @@ lib.makeOverridable ( export MITM_CACHE_CERT_DIR="$PWD" export MITM_CACHE_CA="$MITM_CACHE_CERT_DIR/ca.cer" popd >/dev/null - useBwrap="''${USE_BWRAP:-${toString useBwrap}}" - if [ -n "$useBwrap" ]; then + useBwrap="''${USE_BWRAP:-${if useBwrap then "1" else "0"}}" + if [[ "$useBwrap" -ne 0 ]]; then # bwrap isn't necessary, it's only used to prevent messy build scripts from touching ~ bwrap \ --unshare-all --share-net --clearenv --chdir / --setenv HOME /homeless-shelter \