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 mPdMNy/iWmM8kwAAbAwnHQ (envelope-from ) for ; Thu, 27 Oct 2022 21:55:27 +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 KfJiNy/iWmNWnQAA9RJhRA (envelope-from ) for ; Thu, 27 Oct 2022 21:55:27 +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 8EE751032D for ; Thu, 27 Oct 2022 21:55:27 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oo8xF-0000t0-Rb; Thu, 27 Oct 2022 15:54:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oo8x2-0000kb-LX for guix-patches@gnu.org; Thu, 27 Oct 2022 15:54:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oo8mM-0005fE-MX for guix-patches@gnu.org; Thu, 27 Oct 2022 15:43:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oo8mM-00073x-EC for guix-patches@gnu.org; Thu, 27 Oct 2022 15:43:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#57031] [PATCH v3 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: Thu, 27 Oct 2022 19:43: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.166689978027135 (code B ref 57031); Thu, 27 Oct 2022 19:43:02 +0000 Received: (at 57031) by debbugs.gnu.org; 27 Oct 2022 19:43:00 +0000 Received: from localhost ([127.0.0.1]:59417 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oo8mK-00073Z-89 for submit@debbugs.gnu.org; Thu, 27 Oct 2022 15:43:00 -0400 Received: from knopi.disroot.org ([178.21.23.139]:57292) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oo8mE-000738-BE for 57031@debbugs.gnu.org; Thu, 27 Oct 2022 15:42:55 -0400 Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 394DF4E821; Thu, 27 Oct 2022 21:42:53 +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 UTF8SMTP id SBmJFtkuryEX; Thu, 27 Oct 2022 21:42:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1666899771; bh=6NEkYhvLxikMziXYAM8sT06+h0t6jC1dinzPnK4aS3Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=NA1TZ0T5MCFYIBlUhyjnvH5Y6qB/wUFrzYwqPBQjqE8h8uXrAX7rQYQiq2aaECETc z2bxSztnqIte62NNWYvZiUfBwGk8XvuYTihquU0BaNC4a7r1bBeOZQvwLz+rSHrHtE TzNbD7zs65bqlFQPlqve3D6VgW0msqgR5Miljz/mlvrRgYfe2HgSE/GrMx7Rt7zsfI cOv9d1r8J2YOv3VIwDngLYMebq+95EvT3AVfSqbp1ieTZHgDxD+f41g7RMxYMl9dMo +ScYbIpBiaO3WlxLJifiya5ebaLqeO59+v44r56g7+atUE0nj631S9cwAn0jRN8Bfl XhTeWGeD/zetg== Date: Thu, 27 Oct 2022 20:42:43 +0100 Message-Id: <20221027194243.15612-2-paren@disroot.org> In-Reply-To: <20221027194243.15612-1-paren@disroot.org> References: <20221027194243.15612-1-paren@disroot.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: , Sender: "Guix-patches" Reply-to: "\(" X-ACL-Warn: , "\( via Guix-patches" From: "\( via Guix-patches" via Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1666900527; 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:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=3uY4mhOd1bOaOg5z4//afGcDnJgfzKHod2uELpAkvqQ=; b=Hj+pAlX/M4ZqgjGTH/oiIeoFOVLmaSU2pNUSbWAMARemM9PrnSskzv9iXcPO5QFR5UkLWH +1x4RlZG0dPdgGjoGahvg+y/I3OZ5rG2/8T7UfjFt7TjDFzEjsPllemKb2CkH8wVfsva8N ReLIluImrALbOrD57jtLWiMbZF0fk5pzbak3uUec3SZiDWcfmQhNI94TZtpPbPzCkcfLEP TFhyymX38akKHA3p7Z01ktoAtlpHZYEOl0YPm8OxiaARkr9IfMLewbselOXcpljIDcguOC tsH1iBOWsWqbo2OIM1PNU5ZcE/cDLfrLeSsmurcXaBPdepesPn4iU5RDpD+Rnw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1666900527; a=rsa-sha256; cv=none; b=LD5MzoUW2Mx0FvkIJTd843yxaECAoeMPro3OFOg29CZeoVxL/M8slf78bUJK/iDhZA3B9a DEo66LAAgF6DHmUI0/IXifrKLWQM9EukHyGhSPQxKpqseTPUKXT70noKIhB9nunJ0hDkFv qIeXH2+bB7zwvD+jvc37wWvWyVITKmBJTmdAMKTUzAYUyrsI6U64dxge4RjzRCHAwtcgyo BPsex7/q7xmkaLquR1riaa2gANXUc64h+6rQ+PLcBu/wvFgdqVZ3ISNudh5DWPP0wuG4ev SiLcpQONY2ElSQZPu2I7mwLP99G/GseqHThqZp+WFcXDsUREWjWg+iLhS6slpQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=disroot.org header.s=mail header.b=NA1TZ0T5; 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: -1.41 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=disroot.org header.s=mail header.b=NA1TZ0T5; 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: 8EE751032D X-Spam-Score: -1.41 X-Migadu-Scanner: scn1.migadu.com X-TUID: 7nkGnonbGp+z * guix/ui.scm (root-warning): New variable. * 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 | 11 ++++++++--- guix/scripts/pull.scm | 2 ++ guix/scripts/remove.scm | 3 ++- guix/scripts/upgrade.scm | 3 ++- guix/ui.scm | 8 ++++++++ 6 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 b9090307ac..10cf32475b 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. ;;; @@ -1078,12 +1079,16 @@ (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 root-hint? + (root-warning 'package-root-hint)) (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 7b6c58dbc3..98aaf0b377 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. ;;; @@ -826,6 +827,7 @@ (define (no-arguments arg _) (leave (G_ "~A: extraneous argument~%") arg)) (with-error-handling + (root-warning 'pull-root-hint) (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)) diff --git a/guix/ui.scm b/guix/ui.scm index 3512c761d2..0f1a603025 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -142,6 +142,7 @@ (define-module (guix ui) hint-file record-hint hint-given? + root-warning %default-message-language current-message-language @@ -2086,6 +2087,13 @@ (define (hint-given? hint) "Return true if HINT was already given." (file-exists? (hint-file hint))) +(define (root-warning 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~%")))) + ;;; ;;; Command-line option processing. -- 2.38.0