From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id 8D4EO8We72KwqAAAbAwnHQ (envelope-from ) for ; Sun, 07 Aug 2022 13:15:18 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id AF4vO8We72KYawEA9RJhRA (envelope-from ) for ; Sun, 07 Aug 2022 13:15:17 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 5AC8645693 for ; Sun, 7 Aug 2022 13:15:17 +0200 (CEST) Received: from localhost ([::1]:39610 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oKeFY-0000i4-JF for larch@yhetil.org; Sun, 07 Aug 2022 07:15:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58608) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oKeFK-0000hI-Jl for guix-patches@gnu.org; Sun, 07 Aug 2022 07:15:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:46304) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oKeFK-0001w6-Aw for guix-patches@gnu.org; Sun, 07 Aug 2022 07:15:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oKeFK-0000Gy-5L for guix-patches@gnu.org; Sun, 07 Aug 2022 07:15:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#57031] [PATCH] scripts: Show a hint the first time some commands are run as root. Resent-From: "(" Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 07 Aug 2022 11:15:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 57031 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 57031@debbugs.gnu.org Cc: "\(" X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.1659870883999 (code B ref -1); Sun, 07 Aug 2022 11:15:02 +0000 Received: (at submit) by debbugs.gnu.org; 7 Aug 2022 11:14:43 +0000 Received: from localhost ([127.0.0.1]:36053 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oKeF0-0000G2-J5 for submit@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 ) id 1oKeEx-0000Fs-DX for submit@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 ) id 1oKeEx-0000g8-9L for guix-patches@gnu.org; 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 ) id 1oKeEu-0001tp-HW for guix-patches@gnu.org; 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) 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== Date: Sun, 7 Aug 2022 12:14:21 +0100 Message-Id: <20220807111421.14771-1-paren@disroot.org> 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@disroot.org; 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-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+larch=yhetil.org@gnu.org Sender: "Guix-patches" Reply-to: "\(" X-ACL-Warn: , "\( via Guix-patches" From: "\( via Guix-patches" via X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1659870917; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=r5IYRULChza6NNBTdH7qqwhx0/s8GyRmCWKVSJA6fM0=; b=onNnhSnf1eP6LKxCoAWN6M9VQUAnfc3RvxOUYtFpWYHZO9a7SSdBUUn1p6A9k22O//EM0+ vaf5P703lOk6owEHxhaHRqDJNU3+vhDqHrO/lPsB/ENUMJVx+eAuoWBcYQu4eST1dGQavA tgs3gPoG8XOZ45JK/Vk3MLVdh/1jJXhDZkUcwwuer1HpwKxTdQn/iUP1PHdEBq39Q2ypHh LrBosPzWDGu8t416Q3mDgQjAkYyu0BCV67CZ9hSdskj/M7qPeC1psmMvJecMnyyAoE6LKt WcrtZmLQDurmH2FNdXsp7v5geK2J2lrxUiMb4rJZtts3+bkZiQcGXShtOgXh8g== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1659870917; a=rsa-sha256; cv=none; b=uuifQuKOZXdnTwfXNjoSBft26BNOb60YuYG/0Lm2/WqZ+p2Np4T11tXbvKScp8sU067ja6 Yv/zM9l0N+GjlXFDd2trXd9FFwwAu/8DG+lrt5OEK1JcL2HKOnr/6S4G2nMXuciUL9eUXx jggeNOl0UwHBo1vHru4RQrWaHu7GAcOh8v1YMiDbW1LC1wRVTnoKOuVECkr5CLu0uBy4lZ +1hIxmXoZc4NAlXk2+rKICCoEDrxXQc+g9div6pBaYwu05E8J1HVukbT0KJqXfFAPRYPr8 vONCmwFMSo9wJt5igRsWRRcY6wCcfVBKTtZmemLMvtrKFTBMdV9TDS6N9rS/ZQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=disroot.org header.s=mail header.b=BVjevEJD; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -3.10 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=disroot.org header.s=mail header.b=BVjevEJD; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 5AC8645693 X-Spam-Score: -3.10 X-Migadu-Scanner: scn1.migadu.com X-TUID: z5MXB9BPd2Yu * 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 +;;; 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 7d92598efa..8936c70e1f 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. ;;; @@ -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 ;;; Copyright © 2017 Marius Bakke ;;; Copyright © 2020, 2021 Tobias Geerinckx-Rice +;;; Copyright © 2022 ( ;;; ;;; 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 +;;; 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)) 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 ;;; Copyright © 2018 Steve Sprang ;;; Copyright © 2022 Taiju HIGASHI +;;; Copyright © 2022 ( ;;; ;;; 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