From patchwork Sun Sep 11 19:59:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "\\(" X-Patchwork-Id: 42511 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 3B2A527BBEA; Sun, 11 Sep 2022 21:00:18 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id E4D0827BBE9 for ; Sun, 11 Sep 2022 21:00:17 +0100 (BST) Received: from localhost ([::1]:56390 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oXT7n-0001FP-7t for patchwork@mira.cbaines.net; Sun, 11 Sep 2022 16:00:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53462) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oXT7a-0001Eq-R1 for guix-patches@gnu.org; Sun, 11 Sep 2022 16:00:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:54913) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oXT7a-0007ur-DC for guix-patches@gnu.org; Sun, 11 Sep 2022 16:00:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oXT7a-0006PA-4N for guix-patches@gnu.org; Sun, 11 Sep 2022 16:00:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#57031] [PATCH v2 1/2] ui: Make one-time hint API public. References: <20220807111421.14771-1-paren@disroot.org> In-Reply-To: <20220807111421.14771-1-paren@disroot.org> Resent-From: "(" Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 11 Sep 2022 20:00:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 57031 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 57031@debbugs.gnu.org Cc: "\(" Received: via spool by 57031-submit@debbugs.gnu.org id=B57031.166292639124559 (code B ref 57031); Sun, 11 Sep 2022 20:00:02 +0000 Received: (at 57031) by debbugs.gnu.org; 11 Sep 2022 19:59:51 +0000 Received: from localhost ([127.0.0.1]:43610 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oXT7P-0006Nx-3g for submit@debbugs.gnu.org; Sun, 11 Sep 2022 15:59:51 -0400 Received: from knopi.disroot.org ([178.21.23.139]:59702) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oXT7N-0006Nl-23 for 57031@debbugs.gnu.org; Sun, 11 Sep 2022 15:59:49 -0400 Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 33C224A06A; Sun, 11 Sep 2022 21:59:48 +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 ClGgwd7ye4Vc; Sun, 11 Sep 2022 21:59:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1662926386; bh=59Y8FNHYI47zfC+7QOGV/W/vMtqsFtjf/5X+93Cf7yo=; h=From:To:Cc:Subject:Date; b=h+C2SlGEcMApc/ciK39iTaSHPJ1ALuSXQ2oHJ2PhAugrIy8BrePKXXyi9vS8H6+Oj WPl5xTpA6YZAsgb2KSVRwCZ9tmAETJSz3e6kf+rlOEDPAnrxD97mcI78UwT/8tA/k/ NngByrDG9ZhREVpkT1isriGySsJyl/SYOyZ2gnAG6/x79H/pgNADqt5NMH2TmtNiWR PUlW5D+Ex1JjfC6/y0EDy/nQP1bNSfL+t8uX8AM1YWmZ1FWjC+bJNKl8dHhddbMjBG XrVK2r7UxeZOFkc2W5hS5E49TLWVNBX6CEiUlLExYfNtdrbXxMwtpM/zCW630jw7Sp E5f/tf7kVuvGw== Date: Sun, 11 Sep 2022 20:59:40 +0100 Message-Id: <20220911195941.8442-1-paren@disroot.org> Mime-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" Reply-to: "\(" X-ACL-Warn: , "\( via Guix-patches" X-Patchwork-Original-From: "\( via Guix-patches" via From: "\\(" X-getmail-retrieved-from-mailbox: Patches * guix/scripts/shell.scm (hint-directory, hint-file, record-hint, hint-given?): Move these... * guix/ui.scm (hint-directory, hint-file, record-hint, hint-given?): ...here. --- guix/scripts/shell.scm | 23 ----------------------- guix/ui.scm | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 23 deletions(-) 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/ui.scm b/guix/ui.scm index dad2b853ac..3512c761d2 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -19,6 +19,7 @@ ;;; Copyright © 2018 Steve Sprang ;;; Copyright © 2022 Taiju HIGASHI ;;; Copyright © 2022 Liliana Marie Prikler +;;; Copyright © 2022 ( ;;; ;;; This file is part of GNU Guix. ;;; @@ -137,6 +138,11 @@ (define-module (guix ui) switch-to-generation* delete-generation* + hint-directory + hint-file + record-hint + hint-given? + %default-message-language current-message-language @@ -2057,6 +2063,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. From patchwork Sun Sep 11 19:59:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "\\(" X-Patchwork-Id: 42510 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id A44FE27BBEA; Sun, 11 Sep 2022 21:00:16 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 0249327BBE9 for ; Sun, 11 Sep 2022 21:00:16 +0100 (BST) Received: from localhost ([::1]:56388 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oXT7n-0001FF-5k for patchwork@mira.cbaines.net; Sun, 11 Sep 2022 16:00:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53464) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oXT7a-0001Es-Us for guix-patches@gnu.org; Sun, 11 Sep 2022 16:00:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:54914) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oXT7a-0007v2-Lz for guix-patches@gnu.org; Sun, 11 Sep 2022 16:00:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oXT7a-0006PH-I8 for guix-patches@gnu.org; Sun, 11 Sep 2022 16:00:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#57031] [PATCH v2 2/2] scripts: Warn the first time pull or package is run as root. Resent-From: "(" Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 11 Sep 2022 20:00:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 57031 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 57031@debbugs.gnu.org Cc: "\(" Received: via spool by 57031-submit@debbugs.gnu.org id=B57031.166292639524571 (code B ref 57031); Sun, 11 Sep 2022 20:00:02 +0000 Received: (at 57031) by debbugs.gnu.org; 11 Sep 2022 19:59:55 +0000 Received: from localhost ([127.0.0.1]:43612 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oXT7S-0006OE-L6 for submit@debbugs.gnu.org; Sun, 11 Sep 2022 15:59:55 -0400 Received: from knopi.disroot.org ([178.21.23.139]:60004) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oXT7O-0006Nq-7m for 57031@debbugs.gnu.org; Sun, 11 Sep 2022 15:59:51 -0400 Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 89CC74A05F; Sun, 11 Sep 2022 21:59:49 +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 IU8JOtr7iJe5; Sun, 11 Sep 2022 21:59:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1662926386; bh=2OIz/g1AGKdN7bhp06i5QfSAegwJ3pRM6+GN+a7vxZg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=MVV/X8yp+FJg4cM9StVUsBH3EMoCaw2baMHZoj3+ZoDJs0/AIE2l2vZMHXHEg/x8I 5tbSpwTPa6hixMN+y+FKNFOefRGEEXMF0bcWgQfwOEuTbsOKwYciLdjZu7YvFW7s9W WEZC0uzjvve/Yz6RaEhBapG7Pn4/JZKZvVB4MRTae+msTSE/lsvE6KiuprcFYI2skg CIvlXjBVHLbK+Z5BGv2OtvdFGPl+SqNkwi4AA0wrxWRqngX9T+nHHGbo/Ybgz5qsJC utxlV930PAz7iOFUBAtig9JCOlot+UgPCaY3rJmw5Enj/gbJnus4c22SBCylQ5HtSX j0KQ/P9DVlCOA== Date: Sun, 11 Sep 2022 20:59:41 +0100 Message-Id: <20220911195941.8442-2-paren@disroot.org> In-Reply-To: <20220911195941.8442-1-paren@disroot.org> References: <20220911195941.8442-1-paren@disroot.org> Mime-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" Reply-to: "\(" X-ACL-Warn: , "\( via Guix-patches" X-Patchwork-Original-From: "\( via Guix-patches" via From: "\\(" X-getmail-retrieved-from-mailbox: Patches * 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. --- guix/scripts/install.scm | 3 ++- guix/scripts/package.scm | 15 ++++++++++++--- guix/scripts/pull.scm | 6 ++++++ guix/scripts/remove.scm | 3 ++- guix/scripts/upgrade.scm | 3 ++- 5 files changed, 24 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 +;;; Copyright © 2022 ( ;;; ;;; 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 ;;; Copyright © 2022 Josselin Poiret ;;; Copyright © 2022 Antero Mejr +;;; Copyright © 2022 ( ;;; ;;; 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 ;;; Copyright © 2017 Marius Bakke ;;; Copyright © 2020, 2021 Tobias Geerinckx-Rice +;;; Copyright © 2022 ( ;;; ;;; 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 +;;; Copyright © 2022 ( ;;; ;;; 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 ;;; Copyright © 2020 Jakub Kądziołka ;;; Copyright © 2020 Simon Tournier +;;; Copyright © 2022 ( ;;; ;;; 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))