Message ID | 20220911195941.8442-2-paren@disroot.org |
---|---|
State | New |
Headers | show |
Series | [bug#57031,v2,1/2] ui: Make one-time hint API public. | expand |
Context | Check | Description |
---|---|---|
cbaines/comparison | success | View comparision |
cbaines/git-branch | success | View Git branch |
cbaines/applying patch | success | View Laminar job |
cbaines/issue | success | View issue |
Hi, On Sun, 11 Sep 2022 at 20:59, "\( via Guix-patches" via <guix-patches@gnu.org> wrote: > * guix/scripts/pull.scm (guix-pull): Warn the first time it's being > run as root. > * guix/scripts/package.scm (guix-package*): Likewise if the new > `root-hint?' argument is `#t'. > (guix-package): Use `#:root-hint? #t' in invocation of `guix-package*'. > * guix/scripts/install.scm (guix-install): Likewise. > * guix/scripts/remove.scm (guix-remove): Likewise. > * guix/scripts/remove.scm (guix-upgrade): Likewise. > > 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 warning the first time they are run as root. This patch LGTM aside… > - (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? > + (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? Cheers, simon
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) -- (
Hi, On Thu, 27 Oct 2022 at 06:52, "\( via Guix-patches" via <guix-patches@gnu.org> wrote: > 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. Ah, I see. But then, guix package --show=hello would print the hint, no? > ;;;; 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) Something like that SGTM. Cheers, simon
On Thu Oct 27, 2022 at 9:23 AM BST, zimoun wrote: > Ah, I see. But then, > > guix package --show=hello > > would print the hint, no? Sadly, yes. I'm not sure how to remedy this, and it doesn't seem too consequential; I've never seen someone using ``--show'' or ``--search'' in practice. -- (
diff --git a/guix/scripts/install.scm b/guix/scripts/install.scm index 63e625f266..bf11fc7b11 100644 --- a/guix/scripts/install.scm +++ b/guix/scripts/install.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2019, 2020 Ludovic Courtès <ludo@gnu.org> +;;; Copyright © 2022 ( <paren@disroot.org> ;;; ;;; This file is part of GNU Guix. ;;; @@ -80,4 +81,4 @@ (define opts (list %package-default-options #f) #:argument-handler handle-argument)) - (guix-package* opts)) + (guix-package* opts #:root-hint? #t)) diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm index 7ba2661bbb..7379e69388 100644 --- a/guix/scripts/package.scm +++ b/guix/scripts/package.scm @@ -12,6 +12,7 @@ ;;; Copyright © 2018 Steve Sprang <scs@stevesprang.com> ;;; Copyright © 2022 Josselin Poiret <dev@jpoiret.xyz> ;;; Copyright © 2022 Antero Mejr <antero@mailbox.org> +;;; Copyright © 2022 ( <paren@disroot.org> ;;; ;;; This file is part of GNU Guix. ;;; @@ -1079,12 +1080,20 @@ (define opts (parse-command-line args %options (list %default-options #f) #:argument-handler handle-argument)) - (guix-package* opts)) + (guix-package* opts #:root-hint? #t)) -(define (guix-package* opts) +(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)) + (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~%"))) (or (process-query opts) (parameterize ((%store (open-connection)) (%graft? (assoc-ref opts 'graft?))) diff --git a/guix/scripts/pull.scm b/guix/scripts/pull.scm index 19224cf70b..188b632450 100644 --- a/guix/scripts/pull.scm +++ b/guix/scripts/pull.scm @@ -2,6 +2,7 @@ ;;; Copyright © 2013-2015, 2017-2022 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2017 Marius Bakke <mbakke@fastmail.com> ;;; Copyright © 2020, 2021 Tobias Geerinckx-Rice <me@tobias.gr> +;;; Copyright © 2022 ( <paren@disroot.org> ;;; ;;; This file is part of GNU Guix. ;;; @@ -827,6 +828,11 @@ (define (no-arguments arg _) (leave (G_ "~A: extraneous argument~%") arg)) (with-error-handling + (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~%"))) (with-git-error-handling (let* ((opts (parse-command-line args %options (list %default-options) diff --git a/guix/scripts/remove.scm b/guix/scripts/remove.scm index a46ad04d56..131649eace 100644 --- a/guix/scripts/remove.scm +++ b/guix/scripts/remove.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2019, 2020 Ludovic Courtès <ludo@gnu.org> +;;; Copyright © 2022 ( <paren@disroot.org> ;;; ;;; This file is part of GNU Guix. ;;; @@ -76,4 +77,4 @@ (define opts (list %package-default-options #f) #:argument-handler handle-argument)) - (guix-package* opts)) + (guix-package* opts #:root-hint? #t)) diff --git a/guix/scripts/upgrade.scm b/guix/scripts/upgrade.scm index beb59cbe6f..dd14600fe4 100644 --- a/guix/scripts/upgrade.scm +++ b/guix/scripts/upgrade.scm @@ -2,6 +2,7 @@ ;;; Copyright © 2019, 2020 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2020 Jakub Kądziołka <kuba@kadziolka.net> ;;; Copyright © 2020 Simon Tournier <zimon.toutoune@gmail.com> +;;; Copyright © 2022 ( <paren@disroot.org> ;;; ;;; This file is part of GNU Guix. ;;; @@ -87,4 +88,4 @@ (define opts #f) #:argument-handler handle-argument)) - (guix-package* opts)) + (guix-package* opts #:root-hint? #t))