Commit ce96bc54 authored by Paul Liétar's avatar Paul Liétar
Browse files

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.
parent 0acc2fef
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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 \