GNU bug report logs - #60566
guix container with FHS emulation and env vars

Previous Next

Package: guix;

Reported by: jman <jman <at> city17.xyz>

Date: Thu, 5 Jan 2023 04:34:01 UTC

Severity: normal

Done: John Kehayias <john.kehayias <at> protonmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: John Kehayias <john.kehayias <at> protonmail.com>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#60566: closed (guix container with FHS emulation and env vars)
Date: Sun, 15 Jan 2023 23:06:01 +0000
[Message part 1 (text/plain, inline)]
Your message dated Sun, 15 Jan 2023 23:05:13 +0000
with message-id <87wn5n8km5.fsf <at> protonmail.com>
and subject line Re: [PATCH] environment: Fix '--emulate-fhs' option overriding $PATH.
has caused the debbugs.gnu.org bug report #60566,
regarding guix container with FHS emulation and env vars
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
60566: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=60566
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: jman <jman <at> city17.xyz>
To: bug-guix <at> gnu.org
Subject: guix container with FHS emulation and env vars
Date: Wed, 04 Jan 2023 23:33:23 +0100
Hello,

When emulating a FHS I observe that env vars seems to be not preserved. Example,
the following command will not preserve $PATH:

    guix shell --container --emulate-fhs --preserve='^PATH$'

When creating a container *without* emulating a FHS, env vars are available,
example:

    guix shell --container --preserve='^PATH$'

Pastebin log of a sample of this behaviour:
https://paste.sr.ht/~jman/65e7f96c445504e11f55595b237280e0c1e3ad34

ref: https://lists.gnu.org/archive/html/help-guix/2023-01/msg00002.html

Thanks for an opinion on this


[Message part 3 (message/rfc822, inline)]
From: John Kehayias <john.kehayias <at> protonmail.com>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: jman <jman <at> city17.xyz>, 60566-done <at> debbugs.gnu.org
Subject: Re: [PATCH] environment: Fix '--emulate-fhs' option overriding $PATH.
Date: Sun, 15 Jan 2023 23:05:13 +0000
Hi Ludo’,


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

> Hi John,
>
> John Kehayias <john.kehayias <at> 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



This bug report was last modified 2 years and 177 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.