From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id ePIxNsmPyGDt5wAAgWs5BA (envelope-from ) for ; Tue, 15 Jun 2021 13:32:25 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id 8FiPMcmPyGDgeAAA1q6Kng (envelope-from ) for ; Tue, 15 Jun 2021 11:32:25 +0000 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 2DAB42A71B for ; Tue, 15 Jun 2021 13:32:25 +0200 (CEST) Received: from localhost ([::1]:50896 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt7It-0000Op-EH for larch@yhetil.org; Tue, 15 Jun 2021 07:32:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51678) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt7IY-0000Od-3R for guix-patches@gnu.org; Tue, 15 Jun 2021 07:32:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:36975) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt7IX-0006GH-Qd for guix-patches@gnu.org; Tue, 15 Jun 2021 07:32:01 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lt7IX-00025K-Lk for guix-patches@gnu.org; Tue, 15 Jun 2021 07:32:01 -0400 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-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" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1623756745; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=3upLY1EtlI5dwtcIVh+8Gph1QGpPQXSMbo3500DHgPQ=; b=Uo0dR8XRdyLIt3d2ji0ZtLiZznLezxQPZByiClXSgewWjFABu13csEopIIyMsels92f9P7 hzrh5ZMMeNxtCMI+SU3p4A3UVWWuyuLur5iKqZz9vlWK+bgqIErs/lYmmNncPx35ojifnL keE/jHNFcpJ1ksI88En0wcAy8aIoJcfvISlxeqbD4og2CiCb2LG/Si4a8yjD5tBqpVx0wS 1qD9Sk4fXqXohivvzrbMdwv5LlSP/k7882jmFNDP2k5ktdhD9L7jv1jLXZEcHZzhApHxkO 5qKWafMHdwhMBkRHMwxR7mB152ylplwnFZCjoH1MttPBOeWnt3vYgD9FQ9YpIA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1623756745; a=rsa-sha256; cv=none; b=Ly+/93xdBba24/mUgdurFNB36nnCmG17S+eDCWYUpj33OaFRvEa4aaLZQoBfkI4dIRTmOF yv6zZ2lBmLUYs283JyF1LbSo3B1F+8ixBcW71R54Z25rgF7X0mDOMhOU70sgpzBjKYyUFF DktcqLKWH8aKrVzo5KMk9tkei+TATonRv4PZT7DFe0ni80kQN8CbbNwXfG6T9IroK5NCdT LAdtpVWvA4nkwe6hTyLhtMzY6gJylXitNwnmSxBQu3UCp2Pox6K578WcYP818Ai8L+E9ve azss9xBcAkWODKl8/j51KjHzPkPC6/QoYOMtO651JBTDYJ638eFaVmh7Ajp8GA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=tugraz.at header.s=mailrelay header.b=jPHBMxPx; dmarc=fail reason="SPF not aligned (relaxed)" header.from=student.tugraz.at (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: -1.33 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=tugraz.at header.s=mailrelay header.b=jPHBMxPx; dmarc=fail reason="SPF not aligned (relaxed)" header.from=student.tugraz.at (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: 2DAB42A71B X-Spam-Score: -1.33 X-Migadu-Scanner: scn1.migadu.com X-TUID: 4Y7Bcad2TTte 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))