GNU bug report logs - #57031
[PATCH] scripts: Show a hint the first time some commands are run as root.

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: guix-patches; Reported by: "(" <paren@HIDDEN>; Keywords: patch; dated Sun, 7 Aug 2022 11:15:02 UTC; Maintainer for guix-patches is guix-patches@HIDDEN.

Message received at 57031 <at> debbugs.gnu.org:


Received: (at 57031) by debbugs.gnu.org; 7 Aug 2022 11:22:45 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Aug 07 07:22:44 2022
Received: from localhost ([127.0.0.1]:36063 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1oKeMm-0000TO-LK
	for submit <at> debbugs.gnu.org; Sun, 07 Aug 2022 07:22:44 -0400
Received: from knopi.disroot.org ([178.21.23.139]:55070)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <paren@HIDDEN>) id 1oKeMl-0000TG-3S
 for 57031 <at> debbugs.gnu.org; Sun, 07 Aug 2022 07:22:43 -0400
Received: from localhost (localhost [127.0.0.1])
 by disroot.org (Postfix) with ESMTP id 7704044F71;
 Sun,  7 Aug 2022 13:22:42 +0200 (CEST)
X-Virus-Scanned: SPAM Filter at disroot.org
Received: from knopi.disroot.org ([127.0.0.1])
 by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id BMc5quHDxtvw; Sun,  7 Aug 2022 13:22:41 +0200 (CEST)
Mime-Version: 1.0
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail;
 t=1659871361; bh=n8+989l7TlR7dcmumOS3J0LGbhOv2e80OxniX/nZynQ=;
 h=Date:Subject:From:To:References:In-Reply-To;
 b=QIrQ+HFKmJ2qhSxmuNsyoH1TiCn6yUPzV67U77xMXbt2wIt0us9P4Na7kJJFYnMJw
 vR6ZO2RUc4PKcyusDy9UKornwpmzsPU9nzombvOEPN1Ka/GxX5FWlqiuHlN1KMHd5T
 2cOUkDWofo52NttaoLQdZC3CGGoU0MQUtVxYKRIkHbVO8yXxFbC38cfoetGfcCh7ZR
 54IzA9BBnkSvFn/1VJqJN8w/ni6NU/Hi/GFA45P4csKJVIW7nuty/wY+6TBDW89I5j
 NbRav3SKWfNuplaqim5Pat25BDHeZ3ZiDB6mQKQLNj1OpdCvrJxw5W+23d9ilayaTS
 W1SsC4vEW3FFw==
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8
Date: Sun, 07 Aug 2022 12:22:41 +0100
Message-Id: <CLZRAGCJY28H.XICCZHEOIRHQ@guix-aspire>
Subject: Re: [PATCH v2] scripts: Show a hint the first time some commands
 are run as root.
From: "(" <paren@HIDDEN>
To: "(" <paren@HIDDEN>, <57031 <at> debbugs.gnu.org>
References: <20220807111929.15617-1-paren@HIDDEN>
In-Reply-To: <20220807111929.15617-1-paren@HIDDEN>
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 57031
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

This patch tries to solve the same problem as #57016, except instead
of bailing out on `sudo guix pull`, `sudo guix package`, or similar,
it displays a hint the first time they are run advising users that
Guix's package management is per-user.

    -- (




Information forwarded to guix-patches@HIDDEN:
bug#57031; Package guix-patches. Full text available.

Message received at 57031 <at> debbugs.gnu.org:


Received: (at 57031) by debbugs.gnu.org; 7 Aug 2022 11:19:35 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Aug 07 07:19:35 2022
Received: from localhost ([127.0.0.1]:36059 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1oKeJi-0000O6-Jl
	for submit <at> debbugs.gnu.org; Sun, 07 Aug 2022 07:19:35 -0400
Received: from knopi.disroot.org ([178.21.23.139]:52698)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <paren@HIDDEN>) id 1oKeJg-0000Ny-PF
 for 57031 <at> debbugs.gnu.org; Sun, 07 Aug 2022 07:19:33 -0400
Received: from localhost (localhost [127.0.0.1])
 by disroot.org (Postfix) with ESMTP id 24A5844FE6;
 Sun,  7 Aug 2022 13:19:32 +0200 (CEST)
X-Virus-Scanned: SPAM Filter at disroot.org
Received: from knopi.disroot.org ([127.0.0.1])
 by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id OrsBhXYrvaVl; Sun,  7 Aug 2022 13:19:30 +0200 (CEST)
From: "(" <paren@HIDDEN>
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail;
 t=1659871170; bh=Oaqilhtl+xUnLp1X+Xf7qfOo3GvJ9MY28hRuzF1F48E=;
 h=From:To:Cc:Subject:Date;
 b=bTWPO72fAOQuzCauEeumzwIOkPalyO8BvoKLFh68HEHBswWTYu/mZpBSEI32oNayP
 vHJgMI4UqqQPbG/kR1lOWm2aIv0e4vYdWA8JYkAspX/PFYtfyUVEdwN8T/5rHafiHK
 h7pDaRQqJBvR/tqBa5hYtRFwsjgfFA7Ms8VqkyWyIh5+Lr915Qb12pubR9EfDFP7DV
 M8q0oRtns4jgCpWcmYILM0IFw+Q1bydVBVGfcFmvrCGBWlo83Zyp0qouMx68wgA3EN
 hY66lEoiq9w8F3y7ojnRrkYhQgsMY3BREQwttZJEcarrbY45MiNzTVdXpaJBllnRp6
 D6nf9DuOMZNcA==
To: 57031 <at> debbugs.gnu.org
Subject: [PATCH v2] scripts: Show a hint the first time some commands are run
 as root.
Date: Sun,  7 Aug 2022 12:19:29 +0100
Message-Id: <20220807111929.15617-1-paren@HIDDEN>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Spam-Score: 2.0 (++)
X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 the administrator of that system for details.
 Content preview:  * 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?` keywor [...] 
 Content analysis details:   (2.0 points, 10.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 0.0 SPF_HELO_NONE          SPF: HELO does not publish an SPF Record
 2.0 PDS_OTHER_BAD_TLD      Untrustworthy TLDs
 [URI: jpoiret.xyz (xyz)]
 -0.0 SPF_PASS               SPF: sender matches SPF record
X-Debbugs-Envelope-To: 57031
Cc: "\(" <paren@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: 1.0 (+)

* 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.
---
 guix/scripts/install.scm |  3 ++-
 guix/scripts/package.scm | 16 +++++++++++++---
 guix/scripts/pull.scm    |  7 +++++++
 guix/scripts/remove.scm  |  3 ++-
 guix/scripts/shell.scm   | 23 -----------------------
 guix/scripts/upgrade.scm |  3 ++-
 guix/ui.scm              | 29 +++++++++++++++++++++++++++++
 7 files changed, 55 insertions(+), 29 deletions(-)

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@HIDDEN>
+;;; Copyright © 2022 ( <paren@HIDDEN>
 ;;;
 ;;; 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 7d92598efa..8936c70e1f 100644
--- a/guix/scripts/package.scm
+++ b/guix/scripts/package.scm
@@ -12,6 +12,7 @@
 ;;; Copyright © 2018 Steve Sprang <scs@HIDDEN>
 ;;; Copyright © 2022 Josselin Poiret <dev@HIDDEN>
 ;;; Copyright © 2022 Antero Mejr <antero@HIDDEN>
+;;; Copyright © 2022 ( <paren@HIDDEN>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -1077,12 +1078,21 @@ (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))
+               (= (getuid) 0))
+      (record-hint 'package-root-hint)
+      (display-hint (G_ "`guix package' is user-specific, not system-wide,
+so running this command 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 b0cc459d63..6e3d7db7c7 100644
--- a/guix/scripts/pull.scm
+++ b/guix/scripts/pull.scm
@@ -2,6 +2,7 @@
 ;;; Copyright © 2013-2015, 2017-2022 Ludovic Courtès <ludo@HIDDEN>
 ;;; Copyright © 2017 Marius Bakke <mbakke@HIDDEN>
 ;;; Copyright © 2020, 2021 Tobias Geerinckx-Rice <me@HIDDEN>
+;;; Copyright © 2022 ( <paren@HIDDEN>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -834,6 +835,12 @@ (define (no-arguments arg _)
             (current-channels (profile-channels profile))
             (validate-pull    (assoc-ref opts 'validate-pull))
             (authenticate?    (assoc-ref opts 'authenticate-channels?)))
+       (when (and (not (hint-given? 'pull-root-hint))
+                  (= (getuid) 0))
+         (record-hint 'pull-root-hint)
+         (display-hint (G_ "`guix pull' is user-specific, not system-wide;
+running it as root will only affect the `root' user.")))
+
        (cond
         ((assoc-ref opts 'query)
          (process-query opts profile))
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@HIDDEN>
+;;; Copyright © 2022 ( <paren@HIDDEN>
 ;;;
 ;;; 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/shell.scm b/guix/scripts/shell.scm
index c115a00320..3ac7d80eb0 100644
--- a/guix/scripts/shell.scm
+++ b/guix/scripts/shell.scm
@@ -489,29 +489,6 @@ (define (validated-spec spec)
       (exp
        (pretty-print exp port)))))
 
-
-;;;
-;;; One-time hints.
-;;;
-
-(define (hint-directory)
-  "Return the directory name where previously given hints are recorded."
-  (string-append (cache-directory #:ensure? #f) "/hints"))
-
-(define (hint-file hint)
-  "Return the name of the file that marks HINT as already printed."
-  (string-append (hint-directory) "/" (symbol->string hint)))
-
-(define (record-hint hint)
-  "Mark HINT as already given."
-  (let ((file (hint-file hint)))
-    (mkdir-p (dirname file))
-    (close-fdes (open-fdes file (logior O_CREAT O_WRONLY)))))
-
-(define (hint-given? hint)
-  "Return true if HINT was already given."
-  (file-exists? (hint-file hint)))
-
 
 (define-command (guix-shell . args)
   (category development)
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@HIDDEN>
 ;;; Copyright © 2020 Jakub Kądziołka <kuba@HIDDEN>
 ;;; Copyright © 2020 Simon Tournier <zimon.toutoune@HIDDEN>
+;;; Copyright © 2022 ( <paren@HIDDEN>
 ;;;
 ;;; 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))
diff --git a/guix/ui.scm b/guix/ui.scm
index a7acd41440..44607d80d2 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -18,6 +18,7 @@
 ;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@HIDDEN>
 ;;; Copyright © 2018 Steve Sprang <scs@HIDDEN>
 ;;; Copyright © 2022 Taiju HIGASHI <higashi@HIDDEN>
+;;; Copyright © 2022 ( <paren@HIDDEN>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -136,6 +137,11 @@ (define-module (guix ui)
             switch-to-generation*
             delete-generation*
 
+            hint-directory
+            hint-file
+            record-hint
+            hint-given?
+
             %default-message-language
             current-message-language
 
@@ -2032,6 +2038,29 @@ (define* (package-specification->name+version+output spec
                  (package-name->name+version name)))
     (values name version sub-drv)))
 
+
+;;;
+;;; One-time hints.
+;;;
+
+(define (hint-directory)
+  "Return the directory name where previously given hints are recorded."
+  (string-append (cache-directory #:ensure? #f) "/hints"))
+
+(define (hint-file hint)
+  "Return the name of the file that marks HINT as already printed."
+  (string-append (hint-directory) "/" (symbol->string hint)))
+
+(define (record-hint hint)
+  "Mark HINT as already given."
+  (let ((file (hint-file hint)))
+    (mkdir-p (dirname file))
+    (close-fdes (open-fdes file (logior O_CREAT O_WRONLY)))))
+
+(define (hint-given? hint)
+  "Return true if HINT was already given."
+  (file-exists? (hint-file hint)))
+
 
 ;;;
 ;;; Command-line option processing.
-- 
2.37.1





Information forwarded to guix-patches@HIDDEN:
bug#57031; Package guix-patches. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 7 Aug 2022 11:14:43 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Aug 07 07:14:43 2022
Received: from localhost ([127.0.0.1]:36053 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1oKeF0-0000G2-J5
	for submit <at> debbugs.gnu.org; Sun, 07 Aug 2022 07:14:43 -0400
Received: from lists.gnu.org ([209.51.188.17]:55146)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <paren@HIDDEN>) id 1oKeEx-0000Fs-DX
 for submit <at> debbugs.gnu.org; Sun, 07 Aug 2022 07:14:40 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:58594)
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <paren@HIDDEN>) id 1oKeEx-0000g8-9L
 for guix-patches@HIDDEN; Sun, 07 Aug 2022 07:14:39 -0400
Received: from knopi.disroot.org ([178.21.23.139]:34124)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <paren@HIDDEN>) id 1oKeEu-0001tp-HW
 for guix-patches@HIDDEN; Sun, 07 Aug 2022 07:14:39 -0400
Received: from localhost (localhost [127.0.0.1])
 by disroot.org (Postfix) with ESMTP id 6AD7144F79;
 Sun,  7 Aug 2022 13:14:32 +0200 (CEST)
X-Virus-Scanned: SPAM Filter at disroot.org
Received: from knopi.disroot.org ([127.0.0.1])
 by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 1v34r6XHONIK; Sun,  7 Aug 2022 13:14:31 +0200 (CEST)
From: "(" <paren@HIDDEN>
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail;
 t=1659870871; bh=a4OR6X+4gicNOiGfFNkjyP3XnMiOjvybp0Jap0i0VRo=;
 h=From:To:Cc:Subject:Date;
 b=BVjevEJDd3xW91L5vm6h2xNbnodN9lai2TYMAS8gyAjogsc/LqMzIF+rFKAGzuPBL
 FC0L1mfNj6gDM+B4KJVnWMf7Np37MrEiUV6YU2Tschv+Da9ROhzKpZf5aRmhntTUZw
 /Dhp3J1oU7xpam72SBlW3U8hnMO5PXnEVtvFEq6pbhTV0X2nPlDXOripBZzSTOHXqL
 KsRfNGYohga6ivJ6lMdZZBXMrtStSHEe2LZONCRIWb8qMkbeT36SCnU8guFLvVIUvx
 kzk5bY1iL35eUNewuXKBZqKO53utIDznQugYRRRx5qeDa+Q8+Qgf/om4rKWre/v2vh
 E7ofIvKbQ7hHQ==
To: guix-patches@HIDDEN
Subject: [PATCH] scripts: Show a hint the first time some commands are run as
 root.
Date: Sun,  7 Aug 2022 12:14:21 +0100
Message-Id: <20220807111421.14771-1-paren@HIDDEN>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Received-SPF: pass client-ip=178.21.23.139; envelope-from=paren@HIDDEN;
 helo=knopi.disroot.org
X-Spam_score_int: -20
X-Spam_score: -2.1
X-Spam_bar: --
X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001,
 SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 0.6 (/)
X-Debbugs-Envelope-To: submit
Cc: "\(" <paren@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.4 (/)

* 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.
---
 guix/scripts/install.scm |  3 ++-
 guix/scripts/package.scm | 16 +++++++++++++---
 guix/scripts/pull.scm    |  7 +++++++
 guix/scripts/remove.scm  |  3 ++-
 guix/scripts/upgrade.scm |  3 ++-
 guix/ui.scm              | 29 +++++++++++++++++++++++++++++
 6 files changed, 55 insertions(+), 6 deletions(-)

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@HIDDEN>
+;;; Copyright © 2022 ( <paren@HIDDEN>
 ;;;
 ;;; 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 7d92598efa..8936c70e1f 100644
--- a/guix/scripts/package.scm
+++ b/guix/scripts/package.scm
@@ -12,6 +12,7 @@
 ;;; Copyright © 2018 Steve Sprang <scs@HIDDEN>
 ;;; Copyright © 2022 Josselin Poiret <dev@HIDDEN>
 ;;; Copyright © 2022 Antero Mejr <antero@HIDDEN>
+;;; Copyright © 2022 ( <paren@HIDDEN>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -1077,12 +1078,21 @@ (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))
+               (= (getuid) 0))
+      (record-hint 'package-root-hint)
+      (display-hint (G_ "`guix package' is user-specific, not system-wide,
+so running this command 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 b0cc459d63..6e3d7db7c7 100644
--- a/guix/scripts/pull.scm
+++ b/guix/scripts/pull.scm
@@ -2,6 +2,7 @@
 ;;; Copyright © 2013-2015, 2017-2022 Ludovic Courtès <ludo@HIDDEN>
 ;;; Copyright © 2017 Marius Bakke <mbakke@HIDDEN>
 ;;; Copyright © 2020, 2021 Tobias Geerinckx-Rice <me@HIDDEN>
+;;; Copyright © 2022 ( <paren@HIDDEN>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -834,6 +835,12 @@ (define (no-arguments arg _)
             (current-channels (profile-channels profile))
             (validate-pull    (assoc-ref opts 'validate-pull))
             (authenticate?    (assoc-ref opts 'authenticate-channels?)))
+       (when (and (not (hint-given? 'pull-root-hint))
+                  (= (getuid) 0))
+         (record-hint 'pull-root-hint)
+         (display-hint (G_ "`guix pull' is user-specific, not system-wide;
+running it as root will only affect the `root' user.")))
+
        (cond
         ((assoc-ref opts 'query)
          (process-query opts profile))
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@HIDDEN>
+;;; Copyright © 2022 ( <paren@HIDDEN>
 ;;;
 ;;; 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@HIDDEN>
 ;;; Copyright © 2020 Jakub Kądziołka <kuba@HIDDEN>
 ;;; Copyright © 2020 Simon Tournier <zimon.toutoune@HIDDEN>
+;;; Copyright © 2022 ( <paren@HIDDEN>
 ;;;
 ;;; 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))
diff --git a/guix/ui.scm b/guix/ui.scm
index a7acd41440..44607d80d2 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -18,6 +18,7 @@
 ;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@HIDDEN>
 ;;; Copyright © 2018 Steve Sprang <scs@HIDDEN>
 ;;; Copyright © 2022 Taiju HIGASHI <higashi@HIDDEN>
+;;; Copyright © 2022 ( <paren@HIDDEN>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -136,6 +137,11 @@ (define-module (guix ui)
             switch-to-generation*
             delete-generation*
 
+            hint-directory
+            hint-file
+            record-hint
+            hint-given?
+
             %default-message-language
             current-message-language
 
@@ -2032,6 +2038,29 @@ (define* (package-specification->name+version+output spec
                  (package-name->name+version name)))
     (values name version sub-drv)))
 
+
+;;;
+;;; One-time hints.
+;;;
+
+(define (hint-directory)
+  "Return the directory name where previously given hints are recorded."
+  (string-append (cache-directory #:ensure? #f) "/hints"))
+
+(define (hint-file hint)
+  "Return the name of the file that marks HINT as already printed."
+  (string-append (hint-directory) "/" (symbol->string hint)))
+
+(define (record-hint hint)
+  "Mark HINT as already given."
+  (let ((file (hint-file hint)))
+    (mkdir-p (dirname file))
+    (close-fdes (open-fdes file (logior O_CREAT O_WRONLY)))))
+
+(define (hint-given? hint)
+  "Return true if HINT was already given."
+  (file-exists? (hint-file hint)))
+
 
 ;;;
 ;;; Command-line option processing.
-- 
2.37.1





Acknowledgement sent to "(" <paren@HIDDEN>:
New bug report received and forwarded. Copy sent to guix-patches@HIDDEN. Full text available.
Report forwarded to guix-patches@HIDDEN:
bug#57031; Package guix-patches. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Sun, 7 Aug 2022 11:30:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.