Subject: [PATCH] pre-inst-env: Issue a warning if nor run within a guix shell.

From: nomike <[email-masked]>
Date: Thu, 17 Apr 2025 23:36:29 +0200

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(+)

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
-- 
2.49.0