Subject: [bug#57031] [PATCH v2 2/2] scripts: Warn the first time pull or package is run as root.

From: "(" <[email-masked]>
Date: Thu, 27 Oct 2022 06:52:36 +0100

Heya,

On Wed Oct 26, 2022 at 7:14 PM BST, zimoun wrote:
> > -  (guix-package* opts))
> > +  (guix-package* opts #:root-hint? #t))
>
> [...]
>
> > -  (guix-package* opts))
> > +  (guix-package* opts #:root-hint? #t))
>
> [...]
>
> > -(define (guix-package* opts)
> > +(define* (guix-package* opts #:key (root-hint? #f))
>
> Why this ’root-hint?’ argument?  Is it useful or can we drop it?

This allows us to disable root hints for ``guix package'' variants, so eg
``sudo guix show'' will not trigger the root hint.

> > +    (when (and root-hint?
> > +               (not (hint-given? 'package-root-hint))
> > +               (zero? (getuid)))
> > +      (record-hint 'package-root-hint)
> > +      (warning (G_ "this command is user-specific, so running it as root \
> > +will affect only the 'root' user~%")))
>
> [...]
>
> > +    (when (and (not (hint-given? 'pull-root-hint))
> > +               (zero? (getuid)))
> > +      (record-hint 'pull-root-hint)
> > +      (warning (G_ "this command is user-specific, so running it as root \
> > +will affect only the 'root' user~%")))
>
> It looks pretty similar.  Is it possible to avoid the duplication?

...I guess? Maybe we could do something like this?:

  ;;;; guix/scripts.scm

  (define (warn-if-root hint-name)
    (when (and (not (hint-given hint-name))
               (zero? (getuid)))
      (record-hint hint-name)
      (warning (G_ "this command is user-specific, so running it as root \
  > > +will affect only the 'root' user~%"))))

  ;;;; guix/scripts/package.scm

  (when root-hint?
    (warn-if-root 'package-root-hint))

  ;;;; guix/scripts/pull.scm

  (warn-if-root 'pull-root-hint)

    -- (