all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
To: Simon Josefsson <simon@josefsson.org>
Cc: "Mathieu Othacehe" <othacehe@gnu.org>,
	"Ludovic Courtès" <ludo@gnu.org>,
	74962@debbugs.gnu.org, "Josselin Poiret" <dev@jpoiret.xyz>,
	"Janneke Nieuwenhuizen" <janneke@gnu.org>
Subject: [bug#74962] [PATCH v3 4/5] etc/guix-install.sh: Remove 'which' commands from requirements.
Date: Sun, 29 Dec 2024 11:34:17 +0900	[thread overview]
Message-ID: <8734i7i5ee.fsf@gmail.com> (raw)
In-Reply-To: <87v7v6tygi.fsf@kaka.sjd.se> (Simon Josefsson's message of "Thu,  26 Dec 2024 13:34:21 +0100")

Hi Simon,

Simon Josefsson <simon@josefsson.org> writes:

> Ludovic Courtès <ludo@gnu.org> writes:
>
>> Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:
>>
>>> * etc/guix-install.sh (REQUIRE): Remove "which".  Add "nologin".
>>> (sys_create_build_user): Use 'type' instead of 'which'.
>>>
>>> Fixes: <https://issues.guix.gnu.org/74952>
>>> Reported-by: Simon Josefsson <simon@josefsson.org>
>>> Change-Id: I0675716bab3fc22d3289ee7af2cb0ab33a1cee71
>>
>> LGTM.
>
> Using 'type -P' is not POSIX and neither /bin/dash nor /bin/gash
> supports it.  It seems like a GNU bash extension.  Is that okay?

I think it's OK, since we currently mandate Bash, but we could use
'command -v the-command > /dev/null' for the same result, which *is*
POSIX, so perhaps we should use that instead.

> The snippet ends up in the manual as recommendations for users to run on
> different operating systems.  We may want to assume GNU bash to favor
> it, but I'm not sure if that is really helping users.
>
> If 'type -P' is used, shouldn't that really be 'type -fP' to avoid shell
> function expansion?  It isn't all that clear from the man page if -f is
> still needed for -P or not:
>
> https://manpages.debian.org/bookworm/bash/bash.1.en.html#type

I think we'd have to use -f if we want to guard against shell functions
being found instead; but maybe then it's simpler and clearer to just use
'command -v' as I mentioned above.

> Even so 'type' uses hashed names, do they survive sub-shell $()
> execution?  If type is to be used, maybe this should be:
>
>   $(hash -r nologin && type -Pf nologin)
>
> My suggestion was to use 'command -v nologin' which behaviour is
> standard POSIX /bin/sh.  I acknowledge that it has the trouble of
> expanding to an alias if the shell had 'nologin' aliases somehow
> (unlikely but not impossible).

I agree; I'll make the change.  Perhaps adjust the other 'type' usages
also (there was only 2).

>   $(unalias nologin; command -v nologin)
>
> It seems all of the options (which, type -P, command -v) has another
> unwanted property: if 'nologin' is not available in the path, these
> commands expand to the empty string, and that empty string gets passed
> to 'useradd -s STR -c ...' and the user gets an ugly error message about
> '-c' not being a proper shell.

Yuck.

> I wonder what all this solves compared to hard-coding "/" as the login
> shell for the guixbuild user?
>
> Here is source code for nologin, which we seem to make some effort to
> use - is this better than 'false'?
>
> https://github.com/shadow-maint/shadow/blob/master/src/nologin.c

It seems marginally better than using 'false' in that it logs something
to syslog when a login is attempted and fail :-).

> At least I'm happy nobody wants to keep using 'which'.
>
> I am sorry for the rabbit hole :)

Thanks for the comments.  I'll send a reworked version.

-- 
Thanks,
Maxim




  parent reply	other threads:[~2024-12-29  2:36 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-19  6:57 [bug#74962] [PATCH] etc/guix-install.sh: Explicit shebang to use /usr/bin/env Maxim Cournoyer
2024-12-19  7:17 ` [bug#74962] [PATCH 1/3] etc/teams.scm: Add etc/guix-install.sh to installer team scope Maxim Cournoyer
2024-12-19  7:17   ` [bug#74962] [PATCH 2/3] etc/guix-install.sh: Explicit shebang to use /usr/bin/env Maxim Cournoyer
2024-12-19  8:18     ` Janneke Nieuwenhuizen
2024-12-19 12:48       ` Maxim Cournoyer
2024-12-19  7:17   ` [bug#74962] [PATCH 3/3] etc/guix-install.sh: Fix quoting and other issues Maxim Cournoyer
2024-12-26 10:55     ` Ludovic Courtès
2024-12-19  7:45 ` [bug#74962] [PATCH v3 1/5] etc/teams.scm: Add etc/guix-install.sh to installer team scope Maxim Cournoyer
2024-12-19  7:45   ` [bug#74962] [PATCH v3 2/5] etc/guix-install.sh: Explicit shebang to use /usr/bin/env Maxim Cournoyer
2024-12-19  7:45   ` [bug#74962] [PATCH v3 3/5] etc/guix-install.sh: Fix quoting and other issues Maxim Cournoyer
2024-12-26 10:56     ` Ludovic Courtès
2024-12-19  7:45   ` [bug#74962] [PATCH v3 4/5] etc/guix-install.sh: Remove 'which' commands from requirements Maxim Cournoyer
2024-12-26 10:55     ` Ludovic Courtès
2024-12-26 12:34       ` Simon Josefsson via Guix-patches via
2024-12-28 16:53         ` Ludovic Courtès
2024-12-29  2:26           ` Maxim Cournoyer
2024-12-29  2:33             ` Simon Josefsson via Guix-patches via
2024-12-29  2:34         ` Maxim Cournoyer [this message]
2024-12-19  7:45   ` [bug#74962] [PATCH v3 5/5] etc/guix-install.sh: Sort requirements Maxim Cournoyer
2024-12-26 11:00     ` Ludovic Courtès
2024-12-26 10:54 ` [bug#74962] [PATCH] etc/guix-install.sh: Explicit shebang to use /usr/bin/env 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=8734i7i5ee.fsf@gmail.com \
    --to=maxim.cournoyer@gmail.com \
    --cc=74962@debbugs.gnu.org \
    --cc=dev@jpoiret.xyz \
    --cc=janneke@gnu.org \
    --cc=ludo@gnu.org \
    --cc=othacehe@gnu.org \
    --cc=simon@josefsson.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.