Subject: Re: bug#57031: [PATCH] scripts: Show a hint the first time some commands are run as root.

From: Ludovic Courtès <[email-masked]>
Date: Mon, 05 Sep 2022 23:11:11 +0200

Hello,

"(" <[email-masked]> skribis:

> * guix/scripts/shell.scm (hint-given?, hint-directory, hint-file,
>   record-hint): Move these...
> * guix/ui.scm: ...here. Export them.
> * guix/scripts/package.scm (guix-package*): Add `#:root-hint?` keyword
>   argument. Display a hint if Guix is being run as root and `root-hint?`
>   is #t.
> * guix/scripts/install.scm (guix-install): Use `#:root-hint? #t` here...
> * guix/scripts/remove.scm (guix-remove): ...here...
> * guix/scripts/upgrade.scm (guix-upgrade): ...and here.
> * guix/scripts/pull.scm (guix-pull): (guix-pull): Display a hint if
>   Guix is being run as root.
>
> A pretty common beginner mistake, it seems, is assuming that since
> every other package manager you've used requires root for installing,
> removing, and upgrading packages, Guix must too.
>
> This commit tries to make it harder to make such an assumption, by
> making commands such as `pull`, `package`, and `upgrade` display
> a hint the first time they are run as root.

I like this change!

One nitpick: Could you make moving the hint code from shell.scm to
ui.scm a separate commit?

[...]

> +         (display-hint (G_ "`guix pull' is user-specific, not system-wide;
> +running it as root will only affect the `root' user.")))

Please use Texinfo markup in hints: @command{guix pull}, etc.  (Likewise
for the second hint.)

> +(define* (guix-package* opts #:key (root-hint? #f))
>    "Run the 'guix package' command on OPTS, an alist resulting for command-line
> -option processing with 'parse-command-line'."
> +option processing with 'parse-command-line'.  If ROOT-HINT? is #T, a hint is
> +shown on the first usage of this procedure that informs users about Guix's
> +support for per-user package management."
>    (with-error-handling
> +    (when (and root-hint?
> +               (not (hint-given? 'package-root-hint))
> +               (= (getuid) 0))

Unless I’m mistaken, ‘root-hint?’ is always true; should we just remove
it?

BTW, when running ‘sudo guix install’, the hint is going to
~root/.cache/guix, right?

Thanks,
Ludo’.