all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Philip McGrath <philip@philipmcgrath.com>
To: Maxime Devos <maximedevos@telenet.be>, guix <guix-devel@gnu.org>
Cc: Liliana Marie Prikler <liliana.prikler@gmail.com>,
	Liliana Marie Prikler <liliana.prikler@ist.tugraz.at>
Subject: Re: What 'sh' should 'system' use?
Date: Mon, 26 Sep 2022 03:04:54 -0400	[thread overview]
Message-ID: <c77defd0-2db3-6f07-883c-c7fd808d5a56@philipmcgrath.com> (raw)
In-Reply-To: <84acf321-e5b8-a138-0fc4-14e4e849f774@telenet.be>

Hi,


On 9/19/22 08:55, Maxime Devos wrote:
> (4) Stop using 'system' in applications -- instead use whatever the 
> language's equivalent of Guile's system*, execl ... or Guix' 
> 'invoke'. Why?  Because 'system'-like functions requires quoting the
>  command line arguments whereas in 'system*'-like functions you could
>  just pass a list of command line arguments, and it's easy to get the
>  quoting wrong, especially if some of the arguments are generated 
> dynamically.
> 
> As a bonus, this could often remove a dependency on 
> bash{-minimal,-static,}.
> 

I definitely advocate 'system*'-like functions in general. Still,
'system'-like functions exist: I'm advocating that Guix should should
have a consistent answer for how such functions should behave.

(Very occasionally, a program really does want to invoke the shell, such
as when shell expansion is part of an existing API.)

 From a different perspective, this is part of why I've recently been
thinking we should find 'sh' dynamically: most programs/environments
don't, and shouldn't, need bash{-minimal,-static}, so it seems wrong to
make it a mandatory dependency of libc.

On 9/19/22 08:55, Maxime Devos wrote:
> 
> On 19-09-2022 02:13, Philip McGrath wrote:
>> 1) If we want to continue to hard-code a specific shell into 
>> Glibc,
> 
> We do, for reproducibility -- otherwise, the behaviour of the 
> 'system' function depends on whatever is the current /bin/sh, and 
> sometimes /bin/sh is updated (and on some foreign systems it might 
> not even be the bash we are used to).
> 
> [...]
> 
>> 
>> 2) If we want to make 'sh' a weak/dynamic reference, I think we 
>> should strongly consider arranging to make it available at 
>> '/bin/sh' when present. I expect this option would require less 
>> patching of other packages*by far*  than any other approach.
> 
> See (1) (reproducibility) -- also, you would need to modify the 
> daemon for that, so there are compatibility concerns, and then we're
>  stuck with the /bin/sh special case forever (unless breaking 
> compatibility would later be considered acceptable).
> 

I don't think there's a reproducibility problem. Guix already can create
reproducible containers with "/bin/sh" (e.g. 'guix shell coreutils
--container -- ls /bin') and without "/bin/sh" (as in package build
environments).

I haven't investigated whether adding the ability to create "/bin/sh" in
build containers would require modifying the daemon or just sending the
daemon different instructions. However, AIUI, Nix *always* creates
"/bin/sh" in build containers, which makes me further expect that any
change needed to the daemon would be small.

To be clear, I'm not proposing that we always create "/bin/sh" in build
containers. At a low level, I'm suggesting that we add the ability to
create "/bin/sh" when desired. I can imagine one possibility for a
high-level interface would be to create "/bin/sh" by default when an
input provides "bin/sh", and it might turn out that we end up wanting
"/bin/sh" in most or all build containers in practice, but I see those
as secondary questions.

>> and recommendations for how packages should use it: '_PATH_BSHELL' 
>> is the best mechanism I've heard of so far, though I wish it were 
>> standardized, and the fact that it can't be portably assumed to be
>> a string constant could be surprising.
> 
> I consider _not_ using it, and using (4) instead, to be best. If not
>  suitable (for example, because a shell is needed to run an actual 
> shell script), then a plain "sh" looked up in the $PATH (like other 
> binaries) and substitute*-ed by Guix should suffice.
> 

As I said above, I agree that 'system*' should be preferred over
'system' when possible.

There are a few dimensions here that I want to try to pick apart.

When you say:

> a plain "sh" looked up in the $PATH (like other binaries) and 
> substitute*-ed by Guix should suffice

there are a few different things that might mean.

I think you're probably referring to the status quo, where "sh" is
looked up in the 'inputs' or a G-expression equivalent and an absolute
reference to that particular "sh" is embedded into the package being
built. (But, when cross-compiling, that "sh" would not be in the $PATH
in the build environment.)

There's a different question about $PATH vs. _CS_PATH that I'll address
later.

I see at least two reasons to prefer finding "sh" dynamically at run-time.

First, we have other POSIX-like shells packaged in Guix, such as dash,
zsh, and gash. Currently, to create an environment where one of these
shells is used to run 'system'-like functions (e.g. because dash is
supposed to be faster than bash), you would have to recompile everything
that depends on glibc. (Maybe you could craft a very ugly graft.)

Second, sometimes people may want to create environments, images, etc.
without an "sh" available. In some sense this is a special case of using
an alternate shell, but the consequences of the status quo are
especially notable. Currently, practically any environment or image Guix
creates will include bash-static, because glibc refers to it.

For an especially ironic example, consider this note from `info
"(guix)Invoking guix pack"`:


> Note: Singularity _requires_ you to provide ‘/bin/sh’ in the image.
> For that reason, ‘guix pack -f squashfs’ always implies ‘-S
> /bin=bin’.  Thus, your ‘guix pack’ invocation must always start with
> something like:
> 
>     guix pack -f squashfs bash ...
> 
> If you forget the ‘bash’ (or similar) package, ‘singularity run’ and
> ‘singularity exec’ will fail with an unhelpful “no such file or
> directory” message.

Running `guix pack -f squashfs hello` warns you about the lack of a
shell, and indeed the resulting image doesn't contain "/bin/sh" ... but
it does contain
"/gnu/store/720rj90bch716isd8z7lcwrnvz28ap4y-bash-static-5.1.8/bin/sh"!

Furthermore, if you run `guix pack -f squashfs hello bash-static`, the
resulting image contains both
"/gnu/store/720rj90bch716isd8z7lcwrnvz28ap4y-bash-static-5.1.8/bin/sh"
and "/gnu/store/4f304c7dp68hkcp1zi1i07zm8nfvvyp7-bash-static-5.1.8/bin/sh".

> 
>> 
>> 3) If we want a dynamic 'sh' not located at '/bin/sh', I think we 
>> should implement a function similar to '__bionic_get_shell_path()'
>>  and use it for '_PATH_BSHELL', 'system', etc. That begs the 
>> question of how the function should find 'sh', and I don't have an
>>  answer for that.
> 
> How about $PATH?
> 

This is a subtle point, and it depends in some ways on what you are
trying to use the 'sh' for. From the "Rationale" in the POSIX spec for
'confstr' 
<https://pubs.opengroup.org/onlinepubs/9699919799/functions/confstr.html>:

> The original need for this function was to provide a way of finding
> the configuration-defined default value for the environment variable
> PATH. Since PATH can be modified by the user to include directories
> that could contain utilities replacing the standard utilities in the
> Shell and Utilities volume of POSIX.1-2017, applications need a way
> to determine the system-supplied PATH environment variable value that
> contains the correct search path for the standard utilities.

I don't have a strong view about the merits of using PATH or not in 
general, and, again 'confstr' with '_CS_PATH' doesn't currently give a 
useful result on Guix.

For 'sh' specifically, though, there's some set of programs that look at 
$SHELL or /etc/passwd or other mechanisms for a highly-configurable 
choice of shell: those aren't relevant here. This question concerns a 
different set of programs that are looking for a reliable plain-vanilla 
'sh': this may be configured at the level of the environment (OS, 
container, chroot, etc.)---including configuring it not to exist---but 
it's a less fine-grained sort of configuration, and there's a stronger 
expectation that it will be a POSIX-like 'sh' (not fish or 
/usr/sbin/nologin).

It seems POSIX would like 'sh' to be found using '_CS_PATH', but I don't 
know of any programs that actually do that, and it doesn't work on Guix.

Programs in practice seem to look at "/bin/sh", and environments 
configuring it by choosing what (possibly nothing) to put at "/bin/sh" 
from the perspective of programs in that environment.

>> I think we should document the decision (for example, why 
>> 'bash-static' vs. 'bash- minimal'?)
> 
> Because cycles -- bash-minimal is linked to a (shared) glibc, which 
> is a separate package from bash-minimal, so glibc cannot use 
> bash-minimal, it uses bash-static instead which is linked to a 
> (static) glibc (which might use a bootstrap bash (not 100% sure), but
> it's statically linked, so no reference to the bootstrap bash remains
> IIUC).
> 
> Also, why?  This is an implementation detail.  Who would the target 
> audience be for this documentation?
> 

I don't mean "document the decision" to necessarily imply something 
elaborate or formal, but I think the next person packaging a language 
with a function like 'system' in its standard library shouldn't have to 
reevaluate these questions from scratch. Also, if we decided the right 
thing were to advocate for upstreams to do something differently for the 
sake of portability (e.g. trying to get people to use _CS_PATH---which 
I'm not suggesting), it would help to have a rationale to point to.

Specifically with respect to bash-minimal vs. bash-static, I'm still not 
clear on when I should use which. The package descriptions are 
identical, and I haven't found a clear (to me, at least) explanation in 
the source code comments. For example, if bash-static is needed to avoid 
a cycle as you say, what is the benefit of also having bash-minimal?

-Philip


  reply	other threads:[~2022-09-26  7:48 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-19  0:13 What 'sh' should 'system' use? Philip McGrath
2022-09-19  7:07 ` Liliana Marie Prikler
2022-09-26  8:07   ` Philip McGrath
2022-09-26 10:04     ` Liliana Marie Prikler
2022-09-19 12:55 ` Maxime Devos
2022-09-26  7:04   ` Philip McGrath [this message]
2022-09-26  9:41     ` Liliana Marie Prikler
2022-09-26 12:24     ` Maxime Devos
2022-10-01 16:54 ` Ludovic Courtès
2022-10-15 23:23   ` Philip McGrath
2022-10-16  7:04     ` Liliana Marie Prikler
2022-10-16  7:56       ` Philip McGrath
2022-10-16  8:23         ` Liliana Marie Prikler
2022-10-19 15:30     ` Ludovic Courtès

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=c77defd0-2db3-6f07-883c-c7fd808d5a56@philipmcgrath.com \
    --to=philip@philipmcgrath.com \
    --cc=guix-devel@gnu.org \
    --cc=liliana.prikler@gmail.com \
    --cc=liliana.prikler@ist.tugraz.at \
    --cc=maximedevos@telenet.be \
    /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.