From unknown Sat Aug 16 20:01:46 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#49034] [PATCH] profiles: Add 'load-profile'. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 15 Jun 2021 08:14:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 49034 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 49034@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.16237448155253 (code B ref -1); Tue, 15 Jun 2021 08:14:01 +0000 Received: (at submit) by debbugs.gnu.org; 15 Jun 2021 08:13:35 +0000 Received: from localhost ([127.0.0.1]:48345 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lt4CV-0001Mc-0R for submit@debbugs.gnu.org; Tue, 15 Jun 2021 04:13:35 -0400 Received: from lists.gnu.org ([209.51.188.17]:37302) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lt4CT-0001MV-25 for submit@debbugs.gnu.org; Tue, 15 Jun 2021 04:13:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40446) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt4CP-0004Dk-Ff for guix-patches@gnu.org; Tue, 15 Jun 2021 04:13:32 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:46686) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt4CO-0000eS-EG; Tue, 15 Jun 2021 04:13:28 -0400 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=58476 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt4CN-0008VB-Hc; Tue, 15 Jun 2021 04:13:28 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Tue, 15 Jun 2021 10:13:16 +0200 Message-Id: <20210615081316.17513-1-ludo@gnu.org> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) * guix/profiles.scm (%precious-variables): New variable. (purify-environment, load-profile): New procedures. * guix/scripts/environment.scm (%precious-variables) (purify-environment, create-environment): Remove. (launch-environment): Call 'load-profile' instead of 'create-environment'. * tests/profiles.scm ("load-profile"): New test. --- guix/profiles.scm | 41 +++++++++++++++++++++++++++++ guix/scripts/environment.scm | 51 ++++++------------------------------ tests/profiles.scm | 27 +++++++++++++++++++ 3 files changed, 76 insertions(+), 43 deletions(-) Hi! While explaining the profile bit of the ‘render-videos.scm’ example at , I realized we were missing a helper to “load” a profile—i.e., set all its environment variables. This patch moves said helper from (guix scripts environment) to (guix profiles) and streamlines it. Thoughts? Ludo’. diff --git a/guix/profiles.scm b/guix/profiles.scm index 8cbffa4d2b..09b2d1525a 100644 --- a/guix/profiles.scm +++ b/guix/profiles.scm @@ -11,6 +11,7 @@ ;;; Copyright © 2019 Kyle Meyer ;;; Copyright © 2019 Mathieu Othacehe ;;; Copyright © 2020 Danny Milosavljevic +;;; Copyright © 2014 David Thompson ;;; ;;; This file is part of GNU Guix. ;;; @@ -54,6 +55,7 @@ #:use-module (srfi srfi-26) #:use-module (srfi srfi-34) #:use-module (srfi srfi-35) + #:autoload (srfi srfi-98) (get-environment-variables) #:export (&profile-error profile-error? profile-error-profile @@ -127,6 +129,7 @@ %default-profile-hooks profile-derivation profile-search-paths + load-profile profile profile? @@ -1916,6 +1919,44 @@ already effective." (evaluate-search-paths (manifest-search-paths manifest) (list profile) getenv)) +(define %precious-variables + ;; Environment variables in the default 'load-profile' white list. + '("HOME" "USER" "LOGNAME" "DISPLAY" "TERM" "TZ" "PAGER")) + +(define (purify-environment white-list white-list-regexps) + "Unset all environment variables except those that match the regexps in +WHITE-LIST-REGEXPS and those listed in WHITE-LIST." + (for-each unsetenv + (remove (lambda (variable) + (or (member variable white-list) + (find (cut regexp-exec <> variable) + white-list-regexps))) + (match (get-environment-variables) + (((names . _) ...) + names))))) + +(define* (load-profile profile + #:optional (manifest (profile-manifest profile)) + #:key pure? (white-list-regexps '()) + (white-list %precious-variables)) + "Set the environment variables specified by MANIFEST for PROFILE. When +PURE? is #t, unset the variables in the current environment except those that +match the regexps in WHITE-LIST-REGEXPS and those listed in WHITE-LIST. +Otherwise, augment existing environment variables with additional search +paths." + (when pure? + (purify-environment white-list white-list-regexps)) + (for-each (match-lambda + ((($ variable _ separator) . value) + (let ((current (getenv variable))) + (setenv variable + (if (and current (not pure?)) + (if separator + (string-append value separator current) + value) + value))))) + (profile-search-paths profile manifest))) + (define (profile-regexp profile) "Return a regular expression that matches PROFILE's name and number." (make-regexp (string-append "^" (regexp-quote (basename profile)) diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm index 5ceb86f7a9..6958bd6238 100644 --- a/guix/scripts/environment.scm +++ b/guix/scripts/environment.scm @@ -52,50 +52,9 @@ #:export (assert-container-features guix-environment)) -;; Protect some env vars from purification. Borrowed from nix-shell. -(define %precious-variables - '("HOME" "USER" "LOGNAME" "DISPLAY" "TERM" "TZ" "PAGER")) - (define %default-shell (or (getenv "SHELL") "/bin/sh")) -(define (purify-environment white-list) - "Unset all environment variables except those that match the regexps in -WHITE-LIST and those listed in %PRECIOUS-VARIABLES. A small number of -variables such as 'HOME' and 'USER' are left untouched." - (for-each unsetenv - (remove (lambda (variable) - (or (member variable %precious-variables) - (find (cut regexp-exec <> variable) - white-list))) - (match (get-environment-variables) - (((names . _) ...) - names))))) - -(define* (create-environment profile manifest - #:key pure? (white-list '())) - "Set the environment variables specified by MANIFEST for PROFILE. When -PURE? is #t, unset the variables in the current environment except those that -match the regexps in WHITE-LIST. Otherwise, augment existing environment -variables with additional search paths." - (when pure? - (purify-environment white-list)) - (for-each (match-lambda - ((($ variable _ separator) . value) - (let ((current (getenv variable))) - (setenv variable - (if (and current (not pure?)) - (if separator - (string-append value separator current) - value) - value))))) - (profile-search-paths profile manifest)) - - ;; Give users a way to know that they're in 'guix environment', so they can - ;; adjust 'PS1' accordingly, for instance. Set it to PROFILE so users can - ;; conveniently access its contents. - (setenv "GUIX_ENVIRONMENT" profile)) - (define* (show-search-paths profile manifest #:key pure?) "Display the search paths of MANIFEST applied to PROFILE. When PURE? is #t, do not augment existing environment variables with additional search paths." @@ -425,8 +384,14 @@ regexps in WHITE-LIST." ;; Properly handle SIGINT, so pressing C-c in an interactive terminal ;; application works. (sigaction SIGINT SIG_DFL) - (create-environment profile manifest - #:pure? pure? #:white-list white-list) + (load-profile profile manifest + #:pure? pure? #:white-list-regexps white-list) + + ;; Give users a way to know that they're in 'guix environment', so they can + ;; adjust 'PS1' accordingly, for instance. Set it to PROFILE so users can + ;; conveniently access its contents. + (setenv "GUIX_ENVIRONMENT" profile) + (match command ((program . args) (apply execlp program program args)))) diff --git a/tests/profiles.scm b/tests/profiles.scm index ce77711d63..1a06ff88f3 100644 --- a/tests/profiles.scm +++ b/tests/profiles.scm @@ -279,6 +279,33 @@ (string=? (dirname (readlink bindir)) (derivation->output-path guile)))))) +(test-assertm "load-profile" + (mlet* %store-monad + ((entry -> (package->manifest-entry %bootstrap-guile)) + (guile (package->derivation %bootstrap-guile)) + (drv (profile-derivation (manifest (list entry)) + #:hooks '() + #:locales? #f)) + (profile -> (derivation->output-path drv)) + (bindir -> (string-append profile "/bin")) + (_ (built-derivations (list drv)))) + (define-syntax-rule (with-environment-excursion exp ...) + (let ((env (environ))) + (dynamic-wind + (const #t) + (lambda () exp ...) + (lambda () (environ env))))) + + (return (and (with-environment-excursion + (load-profile profile) + (and (string-prefix? (string-append bindir ":") + (getenv "PATH")) + (getenv "GUILE_LOAD_PATH"))) + (with-environment-excursion + (load-profile profile #:pure? #t #:white-list '()) + (equal? (list (string-append "PATH=" bindir)) + (environ))))))) + (test-assertm "" (mlet* %store-monad ((entry -> (package->manifest-entry %bootstrap-guile)) -- 2.32.0 From unknown Sat Aug 16 20:01:46 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#49034] [PATCH] profiles: Add 'load-profile'. Resent-From: Leo Prikler Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 15 Jun 2021 11:32:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49034 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Ludovic =?UTF-8?Q?Court=C3=A8s?= , 49034@debbugs.gnu.org Received: via spool by 49034-submit@debbugs.gnu.org id=B49034.16237566996942 (code B ref 49034); Tue, 15 Jun 2021 11:32:01 +0000 Received: (at 49034) by debbugs.gnu.org; 15 Jun 2021 11:31:39 +0000 Received: from localhost ([127.0.0.1]:48521 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lt7IA-0001nG-B1 for submit@debbugs.gnu.org; Tue, 15 Jun 2021 07:31:39 -0400 Received: from mailrelay.tugraz.at ([129.27.2.202]:36831) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lt7I8-0001kV-3j for 49034@debbugs.gnu.org; Tue, 15 Jun 2021 07:31:37 -0400 Received: from [10.0.0.4] (62-116-34-49.adsl.highway.telekom.at [62.116.34.49]) by mailrelay.tugraz.at (Postfix) with ESMTPSA id 4G45kD215Mz1LBCr; Tue, 15 Jun 2021 13:31:32 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 mailrelay.tugraz.at 4G45kD215Mz1LBCr DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tugraz.at; s=mailrelay; t=1623756692; bh=3upLY1EtlI5dwtcIVh+8Gph1QGpPQXSMbo3500DHgPQ=; h=Subject:From:To:Date:In-Reply-To:References:From; b=jPHBMxPxbD7RBPf+W/jIdmDIqzot1MxiKY3IhqO/VA3F1c4irpspdzMIbOjapVfuf hHP4Ap2GLnua0uM+ROM3nfkCrCpfhmtCCtd7AzfF9R/VHh3bf0WuLBpxhsA6HCFsxt 6qHh072iL1ti30qJqMGmBwoMqvjn3+4UsfB2aa1c= Message-ID: <0f8c15f365821b615c166b13ed84df9de4130e9b.camel@student.tugraz.at> From: Leo Prikler Date: Tue, 15 Jun 2021 13:31:06 +0200 In-Reply-To: <20210615081316.17513-1-ludo@gnu.org> References: <20210615081316.17513-1-ludo@gnu.org> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.34.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TUG-Backscatter-control: bt4lQm5Tva3SBgCuw0EnZw X-Spam-Scanner: SpamAssassin 3.003001 X-Spam-Score-relay: -1.9 X-Scanned-By: MIMEDefang 2.74 on 129.27.10.117 X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Am Dienstag, den 15.06.2021, 10:13 +0200 schrieb Ludovic Courtès: > * guix/profiles.scm (%precious-variables): New variable. > (purify-environment, load-profile): New procedures. > * guix/scripts/environment.scm (%precious-variables) > (purify-environment, create-environment): Remove. > (launch-environment): Call 'load-profile' instead of 'create- > environment'. > * tests/profiles.scm ("load-profile"): New test. > --- > guix/profiles.scm | 41 +++++++++++++++++++++++++++++ > guix/scripts/environment.scm | 51 ++++++-------------------------- > ---- > tests/profiles.scm | 27 +++++++++++++++++++ > 3 files changed, 76 insertions(+), 43 deletions(-) > > Hi! > > While explaining the profile bit of the ‘render-videos.scm’ example > at < > https://guix.gnu.org/en/blog/2021/reproducible-data-processing-pipelines/> > ;, > I realized we were missing a helper to “load” a profile—i.e., set all > its environment variables. > > This patch moves said helper from (guix scripts environment) to > (guix profiles) and streamlines it. > > Thoughts? > > Ludo’. I, for one, welcome this patch. Adding “load-profile” to (guix profiles) will improve the multi-profile use-case, as one will be able to use it from a Guile REPL or a shell wrapper. Regards, Leo > diff --git a/guix/profiles.scm b/guix/profiles.scm > index 8cbffa4d2b..09b2d1525a 100644 > --- a/guix/profiles.scm > +++ b/guix/profiles.scm > @@ -11,6 +11,7 @@ > ;;; Copyright © 2019 Kyle Meyer > ;;; Copyright © 2019 Mathieu Othacehe > ;;; Copyright © 2020 Danny Milosavljevic > +;;; Copyright © 2014 David Thompson > ;;; > ;;; This file is part of GNU Guix. > ;;; > @@ -54,6 +55,7 @@ > #:use-module (srfi srfi-26) > #:use-module (srfi srfi-34) > #:use-module (srfi srfi-35) > + #:autoload (srfi srfi-98) (get-environment-variables) > #:export (&profile-error > profile-error? > profile-error-profile > @@ -127,6 +129,7 @@ > %default-profile-hooks > profile-derivation > profile-search-paths > + load-profile > > profile > profile? > @@ -1916,6 +1919,44 @@ already effective." > (evaluate-search-paths (manifest-search-paths manifest) > (list profile) getenv)) > > +(define %precious-variables > + ;; Environment variables in the default 'load-profile' white list. > + '("HOME" "USER" "LOGNAME" "DISPLAY" "TERM" "TZ" "PAGER")) > + > +(define (purify-environment white-list white-list-regexps) > + "Unset all environment variables except those that match the > regexps in > +WHITE-LIST-REGEXPS and those listed in WHITE-LIST." > + (for-each unsetenv > + (remove (lambda (variable) > + (or (member variable white-list) > + (find (cut regexp-exec <> variable) > + white-list-regexps))) > + (match (get-environment-variables) > + (((names . _) ...) > + names))))) > + > +(define* (load-profile profile > + #:optional (manifest (profile-manifest > profile)) > + #:key pure? (white-list-regexps '()) > + (white-list %precious-variables)) > + "Set the environment variables specified by MANIFEST for > PROFILE. When > +PURE? is #t, unset the variables in the current environment except > those that > +match the regexps in WHITE-LIST-REGEXPS and those listed in WHITE- > LIST. > +Otherwise, augment existing environment variables with additional > search > +paths." > + (when pure? > + (purify-environment white-list white-list-regexps)) > + (for-each (match-lambda > + ((($ variable _ separator) > . value) > + (let ((current (getenv variable))) > + (setenv variable > + (if (and current (not pure?)) > + (if separator > + (string-append value separator > current) > + value) > + value))))) > + (profile-search-paths profile manifest))) > + > (define (profile-regexp profile) > "Return a regular expression that matches PROFILE's name and > number." > (make-regexp (string-append "^" (regexp-quote (basename profile)) > diff --git a/guix/scripts/environment.scm > b/guix/scripts/environment.scm > index 5ceb86f7a9..6958bd6238 100644 > --- a/guix/scripts/environment.scm > +++ b/guix/scripts/environment.scm > @@ -52,50 +52,9 @@ > #:export (assert-container-features > guix-environment)) > > -;; Protect some env vars from purification. Borrowed from nix- > shell. > -(define %precious-variables > - '("HOME" "USER" "LOGNAME" "DISPLAY" "TERM" "TZ" "PAGER")) > - > (define %default-shell > (or (getenv "SHELL") "/bin/sh")) > > -(define (purify-environment white-list) > - "Unset all environment variables except those that match the > regexps in > -WHITE-LIST and those listed in %PRECIOUS-VARIABLES. A small number > of > -variables such as 'HOME' and 'USER' are left untouched." > - (for-each unsetenv > - (remove (lambda (variable) > - (or (member variable %precious-variables) > - (find (cut regexp-exec <> variable) > - white-list))) > - (match (get-environment-variables) > - (((names . _) ...) > - names))))) > - > -(define* (create-environment profile manifest > - #:key pure? (white-list '())) > - "Set the environment variables specified by MANIFEST for > PROFILE. When > -PURE? is #t, unset the variables in the current environment except > those that > -match the regexps in WHITE-LIST. Otherwise, augment existing > environment > -variables with additional search paths." > - (when pure? > - (purify-environment white-list)) > - (for-each (match-lambda > - ((($ variable _ separator) > . value) > - (let ((current (getenv variable))) > - (setenv variable > - (if (and current (not pure?)) > - (if separator > - (string-append value separator > current) > - value) > - value))))) > - (profile-search-paths profile manifest)) > - > - ;; Give users a way to know that they're in 'guix environment', so > they can > - ;; adjust 'PS1' accordingly, for instance. Set it to PROFILE so > users can > - ;; conveniently access its contents. > - (setenv "GUIX_ENVIRONMENT" profile)) > - > (define* (show-search-paths profile manifest #:key pure?) > "Display the search paths of MANIFEST applied to PROFILE. When > PURE? is #t, > do not augment existing environment variables with additional search > paths." > @@ -425,8 +384,14 @@ regexps in WHITE-LIST." > ;; Properly handle SIGINT, so pressing C-c in an interactive > terminal > ;; application works. > (sigaction SIGINT SIG_DFL) > - (create-environment profile manifest > - #:pure? pure? #:white-list white-list) > + (load-profile profile manifest > + #:pure? pure? #:white-list-regexps white-list) > + > + ;; Give users a way to know that they're in 'guix environment', so > they can > + ;; adjust 'PS1' accordingly, for instance. Set it to PROFILE so > users can > + ;; conveniently access its contents. > + (setenv "GUIX_ENVIRONMENT" profile) > + > (match command > ((program . args) > (apply execlp program program args)))) > diff --git a/tests/profiles.scm b/tests/profiles.scm > index ce77711d63..1a06ff88f3 100644 > --- a/tests/profiles.scm > +++ b/tests/profiles.scm > @@ -279,6 +279,33 @@ > (string=? (dirname (readlink bindir)) > (derivation->output-path guile)))))) > > +(test-assertm "load-profile" > + (mlet* %store-monad > + ((entry -> (package->manifest-entry %bootstrap-guile)) > + (guile (package->derivation %bootstrap-guile)) > + (drv (profile-derivation (manifest (list entry)) > + #:hooks '() > + #:locales? #f)) > + (profile -> (derivation->output-path drv)) > + (bindir -> (string-append profile "/bin")) > + (_ (built-derivations (list drv)))) > + (define-syntax-rule (with-environment-excursion exp ...) > + (let ((env (environ))) > + (dynamic-wind > + (const #t) > + (lambda () exp ...) > + (lambda () (environ env))))) > + > + (return (and (with-environment-excursion > + (load-profile profile) > + (and (string-prefix? (string-append bindir ":") > + (getenv "PATH")) > + (getenv "GUILE_LOAD_PATH"))) > + (with-environment-excursion > + (load-profile profile #:pure? #t #:white-list '()) > + (equal? (list (string-append "PATH=" bindir)) > + (environ))))))) > + > (test-assertm "" > (mlet* %store-monad > ((entry -> (package->manifest-entry %bootstrap-guile)) From unknown Sat Aug 16 20:01:46 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#49034] [PATCH] profiles: Add 'load-profile'. Resent-From: zimoun Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 16 Jun 2021 05:27:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49034 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Ludovic =?UTF-8?Q?Court=C3=A8s?= , 49034@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 49034-submit@debbugs.gnu.org id=B49034.16238211635770 (code B ref 49034); Wed, 16 Jun 2021 05:27:02 +0000 Received: (at 49034) by debbugs.gnu.org; 16 Jun 2021 05:26:03 +0000 Received: from localhost ([127.0.0.1]:51216 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ltO3v-0001Uv-5C for submit@debbugs.gnu.org; Wed, 16 Jun 2021 01:26:03 -0400 Received: from mail-wm1-f50.google.com ([209.85.128.50]:53984) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ltO3t-0001UP-52 for 49034@debbugs.gnu.org; Wed, 16 Jun 2021 01:26:01 -0400 Received: by mail-wm1-f50.google.com with SMTP id j18so300632wms.3 for <49034@debbugs.gnu.org>; Tue, 15 Jun 2021 22:26:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version:content-transfer-encoding; bh=mn40g5BJpZBxSg9lcu89RMcBEiT41n7H710q89Qzwlg=; b=YJSfkxHRwznB0gCQTUVuHJgbZTqDb+AxHsYZ5xnVcKnzLjT+ryJObOyio46LKQY6+s nB3OgtjjSpz1p6uxV2THkAt4FgvHjSzVpCgaRhyqYAikwTVrHgnOX2m2PbNj1I5g0OlR K8U4xdUyoFhQN+YL1fm3akmXitBT96UDq48ok8VBvjcQEZlMin6fZGIEQXGSaBK5x0xA cds7oIazLOLXE4Em12hZBId4HV1ykqhJq+0tIlnQXFp9qiOsU9rjlWXJACR6FUbNNEUX 7lWOWXmWTJUDOo4ZK+HmIWjDeYcMXf9OmzwIky7dFow5bHfw1OvvGEaUSrkuJGyZyd5R 8Bfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version:content-transfer-encoding; bh=mn40g5BJpZBxSg9lcu89RMcBEiT41n7H710q89Qzwlg=; b=gMVq1Jqf3LC5+1t9jofTkyLKOPREKNMB/FOHGVXFlNcfM//XN8J9gZE3sxjmmtnnYa tXIYOL8EeZwkLvUn5PPhFRx7YxwEtJlliyJzKkSrp4BV62x9x5QMggiq6RjqZctbDF8r noEVsjfBGDNwKOl/V56C9ovA5qOcSyp9dSsnB1F+45urmnWgrBA2Px3qoaBOrk0C3qsB KeWtRg1wtpGEGuAWBqfqMHDnro62wRm/Fj1gRrqUZL2dFCYYTQRu83+/GkTUalqRAnVJ 2K5GUVEbTlMNLQgSkGqZ2iwglonuHljAFou1ygbDYoYO1r5fRf0R94vf642lGGpcBnaI 9r/A== X-Gm-Message-State: AOAM532T7iC1GFtm+WIpQBaeE59nZsAxCu4wS6agTWZihhB9hkD6g2Q7 DHb8ag847Xm5XpgvTOYAwTI= X-Google-Smtp-Source: ABdhPJy1sPwRih9a9W7tonT9yFNHxiuZD/PLoHzDuyFDYxygKYLxRmad4zrTNqUwPelGXceLXk1BSg== X-Received: by 2002:a05:600c:d0:: with SMTP id u16mr9102988wmm.155.1623821155359; Tue, 15 Jun 2021 22:25:55 -0700 (PDT) Received: from lili ([2a01:e0a:59b:9120:65d2:2476:f637:db1e]) by smtp.gmail.com with ESMTPSA id r2sm904509wrv.39.2021.06.15.22.25.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 22:25:54 -0700 (PDT) From: zimoun In-Reply-To: <20210615081316.17513-1-ludo@gnu.org> References: <20210615081316.17513-1-ludo@gnu.org> Date: Wed, 16 Jun 2021 07:21:33 +0200 Message-ID: <86mtrqjsf6.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Hi, On Tue, 15 Jun 2021 at 10:13, Ludovic Court=C3=A8s wrote: > * guix/profiles.scm (%precious-variables): New variable. > (purify-environment, load-profile): New procedures. > * guix/scripts/environment.scm (%precious-variables) > (purify-environment, create-environment): Remove. > (launch-environment): Call 'load-profile' instead of 'create-environment'. > * tests/profiles.scm ("load-profile"): New test. > --- > guix/profiles.scm | 41 +++++++++++++++++++++++++++++ > guix/scripts/environment.scm | 51 ++++++------------------------------ > tests/profiles.scm | 27 +++++++++++++++++++ > 3 files changed, 76 insertions(+), 43 deletions(-) Neat. LGTM. Cheers, simon From unknown Sat Aug 16 20:01:46 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#49034] [PATCH] profiles: Add 'load-profile'. Resent-From: Maxime Devos Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 16 Jun 2021 10:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49034 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Ludovic =?UTF-8?Q?Court=C3=A8s?= , 49034@debbugs.gnu.org Received: via spool by 49034-submit@debbugs.gnu.org id=B49034.162383877010015 (code B ref 49034); Wed, 16 Jun 2021 10:20:02 +0000 Received: (at 49034) by debbugs.gnu.org; 16 Jun 2021 10:19:30 +0000 Received: from localhost ([127.0.0.1]:51608 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ltSdt-0002bS-V6 for submit@debbugs.gnu.org; Wed, 16 Jun 2021 06:19:30 -0400 Received: from michel.telenet-ops.be ([195.130.137.88]:42170) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ltSdr-0002bJ-3X for 49034@debbugs.gnu.org; Wed, 16 Jun 2021 06:19:28 -0400 Received: from butterfly.local ([213.119.219.216]) by michel.telenet-ops.be with bizsmtp id HmKQ2500M4gjoFH06mKRKy; Wed, 16 Jun 2021 12:19:25 +0200 Message-ID: From: Maxime Devos Date: Wed, 16 Jun 2021 12:19:12 +0200 In-Reply-To: <20210615081316.17513-1-ludo@gnu.org> References: <20210615081316.17513-1-ludo@gnu.org> Content-Type: multipart/signed; micalg="pgp-sha512"; protocol="application/pgp-signature"; boundary="=-7ym8F09msbQQEisgxFxm" User-Agent: Evolution 3.34.2 MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telenet.be; s=r21; t=1623838765; bh=wILziA2FiiQkhmdTCq/5A/MmfLTI79c1yf0aPrPrVI0=; h=Subject:From:To:Date:In-Reply-To:References; b=YEaE1SrYkABx20h2lfCOJWTSNlAKleBrA54OChduY5nfg9D4GYCYeQ2dIM4CeMNI7 B4nVE8t+VdCb1VBqWTJHodppZVirm7Rr1+9Z/HszILdeavZLvpfrMVPe3YrTi40ujw j7I2VRvBGOUy6eGPmhwjWG1N5PE5GAtsD7g+9csUnbIXVFWuU01c0jR1btGxzhDGNo TTMzBCVinkBskZlh30mxyu72LtIRkVgCxJDKTSKcEd2mpD8gAGibXC4QAdC5vYjs8k xJmBFP7Kwp1RJOaWfqnzEOmTN6NjLdoMGJuRy3xcPaCTv941POhDo64EcddeFyzTBN 8F+Gdw1Rf7d0w== X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) --=-7ym8F09msbQQEisgxFxm Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Ludovic Court=C3=A8s schreef op di 15-06-2021 om 10:13 [+0200]: > +(define %precious-variables > + ;; Environment variables in the default 'load-profile' white list. > + '("HOME" "USER" "LOGNAME" "DISPLAY" "TERM" "TZ" "PAGER")) [...] > -;; Protect some env vars from purification. Borrowed from nix-shell. > -(define %precious-variables > - '("HOME" "USER" "LOGNAME" "DISPLAY" "TERM" "TZ" "PAGER")) This is really a separate issue, but I don't understand why "XAUTHORITY" isn't in the list. Without preserving XAUTHORITY, the following won't work (at least on my desktop environment): guix environment --pure --ad-hoc atril -- atril stuff.pdf # No protocol specified # Cannot parse arguments: Cannot open display:=20 But the following does start atril: guix environment --preserve=3DXAUTHORITY --pure --ad-hoc atril -- atril s= tuff.pdf # A window titled =E2=80=98Atril Document Viewer=E2=80=99 Could "XAUTHORITY" be added to the list? Preserving "DISPLAY" but not "XAUTHORITY" seems rather useless to me, at least on my desktop environment. Greetings, Maxime --=-7ym8F09msbQQEisgxFxm Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iI0EABYKADUWIQTB8z7iDFKP233XAR9J4+4iGRcl7gUCYMnQIRccbWF4aW1lZGV2 b3NAdGVsZW5ldC5iZQAKCRBJ4+4iGRcl7shrAQCMW8RRNzL+t6uVmS0MrlHpv4DW 3n2SZYzqPe9YpY0YBAEAm6IS+PanFiGZ+C5uYADZ+hTyWOaxM5HY9E6Ygi4bzAo= =5wpg -----END PGP SIGNATURE----- --=-7ym8F09msbQQEisgxFxm-- From unknown Sat Aug 16 20:01:46 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#49034] [PATCH] profiles: Add 'load-profile'. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 18 Jun 2021 10:46:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49034 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Maxime Devos Cc: 49034@debbugs.gnu.org Received: via spool by 49034-submit@debbugs.gnu.org id=B49034.162401315924550 (code B ref 49034); Fri, 18 Jun 2021 10:46:01 +0000 Received: (at 49034) by debbugs.gnu.org; 18 Jun 2021 10:45:59 +0000 Received: from localhost ([127.0.0.1]:55891 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1luC0c-0006Nu-O4 for submit@debbugs.gnu.org; Fri, 18 Jun 2021 06:45:58 -0400 Received: from eggs.gnu.org ([209.51.188.92]:38326) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1luC0a-0006Nh-FS for 49034@debbugs.gnu.org; Fri, 18 Jun 2021 06:45:58 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:59048) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1luC0U-0005RQ-Lv; Fri, 18 Jun 2021 06:45:51 -0400 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=53784 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1luC0U-0000ah-Eb; Fri, 18 Jun 2021 06:45:50 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= References: <20210615081316.17513-1-ludo@gnu.org> Date: Fri, 18 Jun 2021 12:45:48 +0200 In-Reply-To: (Maxime Devos's message of "Wed, 16 Jun 2021 12:19:12 +0200") Message-ID: <871r8zh2n7.fsf_-_@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hi, Maxime Devos skribis: > Ludovic Court=C3=A8s schreef op di 15-06-2021 om 10:13 [+0200]: >> +(define %precious-variables >> + ;; Environment variables in the default 'load-profile' white list. >> + '("HOME" "USER" "LOGNAME" "DISPLAY" "TERM" "TZ" "PAGER")) > [...] >> -;; Protect some env vars from purification. Borrowed from nix-shell. >> -(define %precious-variables >> - '("HOME" "USER" "LOGNAME" "DISPLAY" "TERM" "TZ" "PAGER")) > > This is really a separate issue, but I don't understand why "XAUTHORITY" > isn't in the list. Without preserving XAUTHORITY, the following won't work > (at least on my desktop environment): > > guix environment --pure --ad-hoc atril -- atril stuff.pdf > # No protocol specified > # Cannot parse arguments: Cannot open display:=20 > > But the following does start atril: > guix environment --preserve=3DXAUTHORITY --pure --ad-hoc atril -- atril= stuff.pdf > # A window titled =E2=80=98Atril Document Viewer=E2=80=99 > > Could "XAUTHORITY" be added to the list? > Preserving "DISPLAY" but not "XAUTHORITY" seems rather useless to me, > at least on my desktop environment. Agreed, I=E2=80=99ll do that. Thanks, Ludo=E2=80=99. From unknown Sat Aug 16 20:01:46 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Subject: bug#49034: closed (Re: bug#49034: [PATCH] profiles: Add 'load-profile'.) Message-ID: References: <87o8c3fjdx.fsf@gnu.org> <20210615081316.17513-1-ludo@gnu.org> X-Gnu-PR-Message: they-closed 49034 X-Gnu-PR-Package: guix-patches X-Gnu-PR-Keywords: patch Reply-To: 49034@debbugs.gnu.org Date: Fri, 18 Jun 2021 12:28:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1624019282-11255-1" This is a multi-part message in MIME format... ------------=_1624019282-11255-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #49034: [PATCH] profiles: Add 'load-profile'. which was filed against the guix-patches package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 49034@debbugs.gnu.org. --=20 49034: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D49034 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1624019282-11255-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 49034-done) by debbugs.gnu.org; 18 Jun 2021 12:27:17 +0000 Received: from localhost ([127.0.0.1]:55984 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1luDaf-0002uI-7E for submit@debbugs.gnu.org; Fri, 18 Jun 2021 08:27:17 -0400 Received: from eggs.gnu.org ([209.51.188.92]:57046) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1luDad-0002ts-Gb for 49034-done@debbugs.gnu.org; Fri, 18 Jun 2021 08:27:15 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:45172) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1luDaY-0001dw-7b for 49034-done@debbugs.gnu.org; Fri, 18 Jun 2021 08:27:10 -0400 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=54444 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1luDaW-0008Li-Pj for 49034-done@debbugs.gnu.org; Fri, 18 Jun 2021 08:27:10 -0400 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: 49034-done@debbugs.gnu.org Subject: Re: bug#49034: [PATCH] profiles: Add 'load-profile'. References: <20210615081316.17513-1-ludo@gnu.org> Date: Fri, 18 Jun 2021 14:27:06 +0200 In-Reply-To: <20210615081316.17513-1-ludo@gnu.org> ("Ludovic =?utf-8?Q?Cou?= =?utf-8?Q?rt=C3=A8s=22's?= message of "Tue, 15 Jun 2021 10:13:16 +0200") Message-ID: <87o8c3fjdx.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 49034-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hi, Ludovic Court=C3=A8s skribis: > * guix/profiles.scm (%precious-variables): New variable. > (purify-environment, load-profile): New procedures. > * guix/scripts/environment.scm (%precious-variables) > (purify-environment, create-environment): Remove. > (launch-environment): Call 'load-profile' instead of 'create-environment'. > * tests/profiles.scm ("load-profile"): New test. > --- > guix/profiles.scm | 41 +++++++++++++++++++++++++++++ > guix/scripts/environment.scm | 51 ++++++------------------------------ > tests/profiles.scm | 27 +++++++++++++++++++ > 3 files changed, 76 insertions(+), 43 deletions(-) Pushed as ee61777a326c3395518dee5e50ffc9c35ae53f3d, thanks everyone! Ludo=E2=80=99. ------------=_1624019282-11255-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 15 Jun 2021 08:13:35 +0000 Received: from localhost ([127.0.0.1]:48345 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lt4CV-0001Mc-0R for submit@debbugs.gnu.org; Tue, 15 Jun 2021 04:13:35 -0400 Received: from lists.gnu.org ([209.51.188.17]:37302) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lt4CT-0001MV-25 for submit@debbugs.gnu.org; Tue, 15 Jun 2021 04:13:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40446) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt4CP-0004Dk-Ff for guix-patches@gnu.org; Tue, 15 Jun 2021 04:13:32 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:46686) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt4CO-0000eS-EG; Tue, 15 Jun 2021 04:13:28 -0400 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=58476 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt4CN-0008VB-Hc; Tue, 15 Jun 2021 04:13:28 -0400 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= To: guix-patches@gnu.org Subject: [PATCH] profiles: Add 'load-profile'. Date: Tue, 15 Jun 2021 10:13:16 +0200 Message-Id: <20210615081316.17513-1-ludo@gnu.org> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: submit Cc: =?UTF-8?q?Ludovic=20Court=C3=A8s?= X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) * guix/profiles.scm (%precious-variables): New variable. (purify-environment, load-profile): New procedures. * guix/scripts/environment.scm (%precious-variables) (purify-environment, create-environment): Remove. (launch-environment): Call 'load-profile' instead of 'create-environment'. * tests/profiles.scm ("load-profile"): New test. --- guix/profiles.scm | 41 +++++++++++++++++++++++++++++ guix/scripts/environment.scm | 51 ++++++------------------------------ tests/profiles.scm | 27 +++++++++++++++++++ 3 files changed, 76 insertions(+), 43 deletions(-) Hi! While explaining the profile bit of the ‘render-videos.scm’ example at , I realized we were missing a helper to “load” a profile—i.e., set all its environment variables. This patch moves said helper from (guix scripts environment) to (guix profiles) and streamlines it. Thoughts? Ludo’. diff --git a/guix/profiles.scm b/guix/profiles.scm index 8cbffa4d2b..09b2d1525a 100644 --- a/guix/profiles.scm +++ b/guix/profiles.scm @@ -11,6 +11,7 @@ ;;; Copyright © 2019 Kyle Meyer ;;; Copyright © 2019 Mathieu Othacehe ;;; Copyright © 2020 Danny Milosavljevic +;;; Copyright © 2014 David Thompson ;;; ;;; This file is part of GNU Guix. ;;; @@ -54,6 +55,7 @@ #:use-module (srfi srfi-26) #:use-module (srfi srfi-34) #:use-module (srfi srfi-35) + #:autoload (srfi srfi-98) (get-environment-variables) #:export (&profile-error profile-error? profile-error-profile @@ -127,6 +129,7 @@ %default-profile-hooks profile-derivation profile-search-paths + load-profile profile profile? @@ -1916,6 +1919,44 @@ already effective." (evaluate-search-paths (manifest-search-paths manifest) (list profile) getenv)) +(define %precious-variables + ;; Environment variables in the default 'load-profile' white list. + '("HOME" "USER" "LOGNAME" "DISPLAY" "TERM" "TZ" "PAGER")) + +(define (purify-environment white-list white-list-regexps) + "Unset all environment variables except those that match the regexps in +WHITE-LIST-REGEXPS and those listed in WHITE-LIST." + (for-each unsetenv + (remove (lambda (variable) + (or (member variable white-list) + (find (cut regexp-exec <> variable) + white-list-regexps))) + (match (get-environment-variables) + (((names . _) ...) + names))))) + +(define* (load-profile profile + #:optional (manifest (profile-manifest profile)) + #:key pure? (white-list-regexps '()) + (white-list %precious-variables)) + "Set the environment variables specified by MANIFEST for PROFILE. When +PURE? is #t, unset the variables in the current environment except those that +match the regexps in WHITE-LIST-REGEXPS and those listed in WHITE-LIST. +Otherwise, augment existing environment variables with additional search +paths." + (when pure? + (purify-environment white-list white-list-regexps)) + (for-each (match-lambda + ((($ variable _ separator) . value) + (let ((current (getenv variable))) + (setenv variable + (if (and current (not pure?)) + (if separator + (string-append value separator current) + value) + value))))) + (profile-search-paths profile manifest))) + (define (profile-regexp profile) "Return a regular expression that matches PROFILE's name and number." (make-regexp (string-append "^" (regexp-quote (basename profile)) diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm index 5ceb86f7a9..6958bd6238 100644 --- a/guix/scripts/environment.scm +++ b/guix/scripts/environment.scm @@ -52,50 +52,9 @@ #:export (assert-container-features guix-environment)) -;; Protect some env vars from purification. Borrowed from nix-shell. -(define %precious-variables - '("HOME" "USER" "LOGNAME" "DISPLAY" "TERM" "TZ" "PAGER")) - (define %default-shell (or (getenv "SHELL") "/bin/sh")) -(define (purify-environment white-list) - "Unset all environment variables except those that match the regexps in -WHITE-LIST and those listed in %PRECIOUS-VARIABLES. A small number of -variables such as 'HOME' and 'USER' are left untouched." - (for-each unsetenv - (remove (lambda (variable) - (or (member variable %precious-variables) - (find (cut regexp-exec <> variable) - white-list))) - (match (get-environment-variables) - (((names . _) ...) - names))))) - -(define* (create-environment profile manifest - #:key pure? (white-list '())) - "Set the environment variables specified by MANIFEST for PROFILE. When -PURE? is #t, unset the variables in the current environment except those that -match the regexps in WHITE-LIST. Otherwise, augment existing environment -variables with additional search paths." - (when pure? - (purify-environment white-list)) - (for-each (match-lambda - ((($ variable _ separator) . value) - (let ((current (getenv variable))) - (setenv variable - (if (and current (not pure?)) - (if separator - (string-append value separator current) - value) - value))))) - (profile-search-paths profile manifest)) - - ;; Give users a way to know that they're in 'guix environment', so they can - ;; adjust 'PS1' accordingly, for instance. Set it to PROFILE so users can - ;; conveniently access its contents. - (setenv "GUIX_ENVIRONMENT" profile)) - (define* (show-search-paths profile manifest #:key pure?) "Display the search paths of MANIFEST applied to PROFILE. When PURE? is #t, do not augment existing environment variables with additional search paths." @@ -425,8 +384,14 @@ regexps in WHITE-LIST." ;; Properly handle SIGINT, so pressing C-c in an interactive terminal ;; application works. (sigaction SIGINT SIG_DFL) - (create-environment profile manifest - #:pure? pure? #:white-list white-list) + (load-profile profile manifest + #:pure? pure? #:white-list-regexps white-list) + + ;; Give users a way to know that they're in 'guix environment', so they can + ;; adjust 'PS1' accordingly, for instance. Set it to PROFILE so users can + ;; conveniently access its contents. + (setenv "GUIX_ENVIRONMENT" profile) + (match command ((program . args) (apply execlp program program args)))) diff --git a/tests/profiles.scm b/tests/profiles.scm index ce77711d63..1a06ff88f3 100644 --- a/tests/profiles.scm +++ b/tests/profiles.scm @@ -279,6 +279,33 @@ (string=? (dirname (readlink bindir)) (derivation->output-path guile)))))) +(test-assertm "load-profile" + (mlet* %store-monad + ((entry -> (package->manifest-entry %bootstrap-guile)) + (guile (package->derivation %bootstrap-guile)) + (drv (profile-derivation (manifest (list entry)) + #:hooks '() + #:locales? #f)) + (profile -> (derivation->output-path drv)) + (bindir -> (string-append profile "/bin")) + (_ (built-derivations (list drv)))) + (define-syntax-rule (with-environment-excursion exp ...) + (let ((env (environ))) + (dynamic-wind + (const #t) + (lambda () exp ...) + (lambda () (environ env))))) + + (return (and (with-environment-excursion + (load-profile profile) + (and (string-prefix? (string-append bindir ":") + (getenv "PATH")) + (getenv "GUILE_LOAD_PATH"))) + (with-environment-excursion + (load-profile profile #:pure? #t #:white-list '()) + (equal? (list (string-append "PATH=" bindir)) + (environ))))))) + (test-assertm "" (mlet* %store-monad ((entry -> (package->manifest-entry %bootstrap-guile)) -- 2.32.0 ------------=_1624019282-11255-1--