all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: John Kehayias via Bug reports for GNU Guix <bug-guix@gnu.org>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: jman <jman@city17.xyz>, 60566-done@debbugs.gnu.org
Subject: bug#60566: [PATCH] environment: Fix '--emulate-fhs' option overriding $PATH.
Date: Sun, 15 Jan 2023 23:05:13 +0000	[thread overview]
Message-ID: <87wn5n8km5.fsf@protonmail.com> (raw)
In-Reply-To: <87ilh99o1g.fsf@gnu.org>

Hi Ludo’,


On Sat, Jan 14, 2023 at 03:41 PM, Ludovic Courtès wrote:

> Hi John,
>
> John Kehayias <john.kehayias@protonmail.com> skribis:
>
> [...]
>
>> -           (setenv "PATH" "/bin:/usr/bin:/sbin:/usr/sbin")
>> +           (setenv "PATH" (string-append "/bin:/usr/bin:/sbin:/usr/sbin"
>> +                                         (when (getenv "PATH")
>> +                                           (string-append ":" (getenv "PATH")))))
>
> Remember that ‘when’ returns *unspecified* when the condition is false,
> so you’d get a type error here when PATH is undefined.
>
> Instead write: (if (getenv "PATH") … "").
>

Ah yes, my Common Lisp showing through and relying on nil instead. Fixed and thanks!

>> +# Test that $PATH inside the container has FHS directories.
>> +guix shell -CF --bootstrap guile-bootstrap \
>> +     -- guile -c '(exit (if (string-contains (getenv "PATH")
>> +                            "/bin:/usr/bin:/sbin:/usr/sbin")
>> +                           0
>> +                           1))'
>
> Even (exit (string=? (getenv "PATH") "/bin:/usr/bin:/sbin:/usr/sbin")).
>

With this patch PATH now gets the FHS directories in addition to what it normally has (like the profile's bin directory). While slightly redundant, this seems to be better than clobbering it. Anyway, so we can't check that the PATH is completely equal here.

>> +# Make sure '--preserve' is honored for $PATH, which the '--emulate-fhs'
>> +# option will modify.  We can't (easily) check the whole $PATH as it will
>> +# differ inside and outside the container, so just check for an added string.
>> +PATH=this-is-a-test:$PATH guix shell -CF --bootstrap guile-bootstrap -E PATH \
>> +     -- guile -c '(exit (if (string-contains (getenv "PATH")
>> +                            "this-is-a-test")
>> +                           0
>> +                           1))'
>
> It might be slightly more concise with ‘env’:
>
>   PATH=/foo $(type -P guix) shell -E ^PATH$ -C coreutils -- env |grep ^PATH=.*:/foo
>
> (I think ‘--bootstrap’ doesn’t buy us much here because we have to
> download/build ‘glibc-for-fhs’ anyway.  ‘--bootstrap’ and
> ‘guile-bootstrap’ are particularly useful for testse that can run
> without network access and without building tons of stuff, as in
> ‘tests/guix-environment.sh’ for instance.)
>

Ah, thanks, that is nicer if we can just use coreutils. I rewrote the previous test to use that as well. Probably some other tests here could use that simplification, but outside of the scope here.

(Side note that 'type' in zsh works differently, one could use 'whence' there or even the built-in 'which'. For the tests we are running with bash or bash compliant here, so it is not a problem.)

> Otherwise LGTM, thanks!
>
> Ludo’.

Thanks again for your careful review! Pushed as 3bfbfa2946aebb7f68c8027ae80f272f6915c94f and closing this issue.

Thanks also for jman for reporting.

John





      reply	other threads:[~2023-01-15 23:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-04 22:33 bug#60566: guix container with FHS emulation and env vars jman via Bug reports for GNU Guix
2023-01-05 21:19 ` bug#60566: [PATCH] environment: Fix '--emulate-fhs' option overriding $PATH John Kehayias via Bug reports for GNU Guix
2023-01-06 23:03   ` Ludovic Courtès
2023-01-13 21:44     ` John Kehayias via Bug reports for GNU Guix
2023-01-14 14:41       ` Ludovic Courtès
2023-01-15 23:05         ` John Kehayias via Bug reports for GNU Guix [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wn5n8km5.fsf@protonmail.com \
    --to=bug-guix@gnu.org \
    --cc=60566-done@debbugs.gnu.org \
    --cc=jman@city17.xyz \
    --cc=john.kehayias@protonmail.com \
    --cc=ludo@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.