[bug#77878] pre-inst-env: Issue a warning if nor run within a guix shell.

Message ID 20250417213637.2085198-1-nomike@nomike.com
State New
Headers
Series [bug#77878] pre-inst-env: Issue a warning if nor run within a guix shell. |

Commit Message

nomike April 17, 2025, 9:36 p.m. UTC
  Change-Id: I9f212b3c665b7d8ac653c44eeafe6fc41da5b8ff
---
When running ./pre-inst-env on a foreign distro not within a guix shell, weird things happen.

```plaintext
$ ./pre-inst-env guix lint nano
guix: lint: command not found
hint: Did you mean `lint'?

Try `guix --help' for more information.
```

This patch changes pre-inst-env to issue a warning in that case, which could be especially helpful for newbies.
Perhaps a pointer to the right place in the documentation would be helpful here as well.

 build-aux/pre-inst-env.in | 5 +++++
 1 file changed, 5 insertions(+)
  

Patch

diff --git a/build-aux/pre-inst-env.in b/build-aux/pre-inst-env.in
index cd90a06cbc..6081d7aaa5 100644
--- a/build-aux/pre-inst-env.in
+++ b/build-aux/pre-inst-env.in
@@ -24,6 +24,11 @@ 
 # Run COMMAND in a pre-installation environment.  Typical use is
 # "./pre-inst-env guix build hello".
 
+# Check whether we currently are in a guix shell and issue a warning if we're not
+if [ -z "$GUIX_ENVIRONMENT" ]; then
+    echo "\e[1mWarning:\e[0m you are not in a guix shell. This may lead to unexpected results." >&2
+fi
+
 # By default we may end up with absolute directory names that contain '..',
 # which get into $GUILE_LOAD_PATH, leading to '..' in the module file names
 # recorded by Guile.  To avoid that, make sure we get a real absolute