Subject: [PATCH 0/2] Support NixOS and others non-FHS Linux distributions

From: Luis Holanda <[email-masked]>
Date: Wed, 27 Jul 2022 17:33:51 -0300

Currently, the project expects Bash to be in /bin/bash, but in certains
Linux distributions, namely NixOS, this path doesn't exist as all
binaries are stored inside /nix/store. The only thing that exists in
/bin in these distros is sh.

This patchset changes all the shebangs to /usr/bin/env bash, which will
work across all distributions.

The first patch changes only what is necessary to have Bazel run
correctly, while the second one changes the remaining scripts so that
contributors using NixOS can execute them without much problem.

Luis Holanda (2):
  Support NixOS and others non-FHS Linux distros
  misc: use /usr/bin/env in scripts

 bin/mod-tidy                 | 2 +-
 ci/lint                      | 4 ++--
 ci/list_toolchains_platforms | 2 +-
 ci/release                   | 2 +-
 ci/test                      | 2 +-
 contrib/makerel              | 2 +-
 release                      | 2 +-
 test/c/test.sh               | 2 +-
 toolchain/defs.bzl           | 2 +-
 9 files changed, 10 insertions(+), 10 deletions(-)

-- 
2.36.1

---

From: Luis Holanda <[email-masked]>
Date: Wed, 27 Jul 2022 17:33:52 -0300

As it expects Bash to be at `/bin/bash`, the current implementation
fails to execute on NixOS, given that there bash is in a non-standard
path (i.g. `/nix/store/<hash>-bash-interactive-<version>/bin/bash`).

This patch specifically changes `/bin/bash` paths to use `/usr/bin/env bash`,
which should give the correct path in every Unix system.

Signed-off-by: Luis Holanda <[email-masked]>
---
 test/c/test.sh     | 2 +-
 toolchain/defs.bzl | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/test/c/test.sh b/test/c/test.sh
index ee67dd3..7cfac79 100755
--- a/test/c/test.sh
+++ b/test/c/test.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
 
 set -euo pipefail
 
diff --git a/toolchain/defs.bzl b/toolchain/defs.bzl
index d200588..f640aa4 100644
--- a/toolchain/defs.bzl
+++ b/toolchain/defs.bzl
@@ -76,7 +76,7 @@ def toolchains(
         },
     )
 
-ZIG_TOOL_WRAPPER = """#!/bin/bash
+ZIG_TOOL_WRAPPER = """#!/usr/bin/env bash
 set -e
 
 if [[ -n "$TMPDIR" ]]; then
-- 
2.36.1

---

From: Luis Holanda <[email-masked]>
Date: Wed, 27 Jul 2022 17:33:53 -0300

This patch continues the work to support NixOS and others non-FHS
distributions by replacing instances of `/bin/bash` with
`/usr/bin/env bash`, which works correctly in more systems than the
former.

Signed-off-by: Luis Holanda <[email-masked]>
---
 bin/mod-tidy                 | 2 +-
 ci/lint                      | 4 ++--
 ci/list_toolchains_platforms | 2 +-
 ci/release                   | 2 +-
 ci/test                      | 2 +-
 contrib/makerel              | 2 +-
 release                      | 2 +-
 7 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/bin/mod-tidy b/bin/mod-tidy
index 0c66f25..b3d0971 100755
--- a/bin/mod-tidy
+++ b/bin/mod-tidy
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
 
 set -xeuo pipefail
 
diff --git a/ci/lint b/ci/lint
index 8c52243..f84eaa1 100755
--- a/ci/lint
+++ b/ci/lint
@@ -1,9 +1,9 @@
-#!/bin/bash
+#!/usr/bin/env bash
 set -euo pipefail
 
 REPO_ROOT=$(git rev-parse --show-toplevel)
 cd "$REPO_ROOT"
 
 # shellcheck disable=SC2046
-shellcheck -x $(awk '/#!\/bin\/(ba)?sh/&&FNR==1{print FILENAME}' $(git ls-files))
+shellcheck -x $(awk '/#!\/usr\/bin\/env/&&FNR==1{print FILENAME}' $(git ls-files))
 find . \( -name 'WORKSPACE' -o -name 'BUILD' -o -name '*.bzl' \) -exec buildifier {} +
diff --git a/ci/list_toolchains_platforms b/ci/list_toolchains_platforms
index a7d0342..fae9ab8 100755
--- a/ci/list_toolchains_platforms
+++ b/ci/list_toolchains_platforms
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
 set -euo pipefail
 
 indent() { sed 's/^/    /'; }
diff --git a/ci/release b/ci/release
index 5149c64..b166828 100755
--- a/ci/release
+++ b/ci/release
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
 set -xeuo pipefail
 
 cd "$(git rev-parse --show-toplevel)"
diff --git a/ci/test b/ci/test
index 269510d..5aaac7a 100755
--- a/ci/test
+++ b/ci/test
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
 set -xeuo pipefail
 
 bazel test ...
diff --git a/contrib/makerel b/contrib/makerel
index 045b422..de614db 100755
--- a/contrib/makerel
+++ b/contrib/makerel
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
 set -euo pipefail
 
 zigdir=out/zig-x86_64-linux-musl-x86_64_v3
diff --git a/release b/release
index c3a4976..d49de26 100755
--- a/release
+++ b/release
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
 set -xeuo pipefail
 
 sign=(-u [email-masked])
-- 
2.36.1

---

From: Motiejus Jakštys <[email-masked]>
Date: Thu, 28 Jul 2022 12:47:05 -0700

>   misc: use /usr/bin/env in scripts

Thanks, applied.

For next time don't sign-off -- that's unnecessary here.

Motiejus

---

From: Luis Holanda <[email-masked]>
Date: Thu, 28 Jul 2022 16:54:01 -0300

> For next time don't sign-off -- that's unnecessary here.

Thanks for the advice, first contribution in Source Hut.