From unknown Thu Aug 21 12:12:05 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#60341] [PATCH Home] home: services: environment-variables: Add support for literal strings. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 26 Dec 2022 18:21:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 60341 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 60341@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.167207880315499 (code B ref -1); Mon, 26 Dec 2022 18:21:01 +0000 Received: (at submit) by debbugs.gnu.org; 26 Dec 2022 18:20:03 +0000 Received: from localhost ([127.0.0.1]:54098 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p9s4w-00041s-LZ for submit@debbugs.gnu.org; Mon, 26 Dec 2022 13:20:03 -0500 Received: from lists.gnu.org ([209.51.188.17]:39598) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p9s4u-00041P-50 for submit@debbugs.gnu.org; Mon, 26 Dec 2022 13:20:01 -0500 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 1p9s4m-0005fx-CG for guix-patches@gnu.org; Mon, 26 Dec 2022 13:19:52 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p9s4j-0005fs-Ih; Mon, 26 Dec 2022 13:19:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=w16Xa9XGXEA31PBhkbHgKl9B6mn/HRUFLEYGIdf8cuo=; b=e4Tb0rSj7k6KJG PCazL8Z3Ks0LcuzLxDFz2sIURMxRXLPX4k4xd/uGCjE4SlteZGcrqS4RSPR6j7JY7VB5yVT5VdXf3 t4MkF92kP6n+y6BLzqD+nZRpk//1rgRJbV3qg2rR8qPbWyottSONw7W2JoLtz4E+TTyyQr4VntexT a1b9/jg7TIEtXaMIh8YYFtOMxCnUP2j6Pp7Aqsd9QrOAf3elRSeMpGQL8024P1c990c8pI1a9ZpXk 2jDalD14z2S4Q+cXRlWMK6YsFQNOxq58XWBtfJ/oxevzKl/3wCbrUTqVYwq130rG4nGYbcV+Mgiv/ x+G2GI5ho0o7RjrrM/mA==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201] 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 1p9s4h-0007Fq-RZ; Mon, 26 Dec 2022 13:19:48 -0500 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Mon, 26 Dec 2022 19:19:38 +0100 Message-Id: <20221226181938.30003-1-ludo@gnu.org> X-Mailer: git-send-email 2.38.1 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 (---) * gnu/home/services.scm (): New record type. (environment-variable-shell-definitions): Split 'shell-quote' into 'quote-string' and 'shell-double-quote'. Add 'shell-single-quote'. Add clause for 'literal-string' records. * tests/guix-home.sh: Test it. * doc/guix.texi (Essential Home Services): Document it. --- doc/guix.texi | 14 ++++++++++--- gnu/home/services.scm | 48 ++++++++++++++++++++++++++++++++----------- tests/guix-home.sh | 4 +++- 3 files changed, 50 insertions(+), 16 deletions(-) Hi! I found that it’s occasionally useful to be able to define shell variables with a value that is to be taken literally, without shell expansion. This is what this patch implements. Thoughts? Ludo’. diff --git a/doc/guix.texi b/doc/guix.texi index efd281d9b0..44361b481a 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -40972,13 +40972,15 @@ The easiest way to extend a service type, without defining a new service type is to use the @code{simple-service} helper from @code{(gnu services)}. +@findex literal-string @lisp (simple-service 'some-useful-env-vars-service home-environment-variables-service-type `(("LESSHISTFILE" . "$XDG_CACHE_HOME/.lesshst") ("SHELL" . ,(file-append zsh "/bin/zsh")) ("USELESS_VAR" . #f) - ("_JAVA_AWT_WM_NONREPARENTING" . #t))) + ("_JAVA_AWT_WM_NONREPARENTING" . #t) + ("LITERAL_VALUE" . ,(literal-string "$@{abc@}")))) @end lisp If you include such a service in you home environment definition, it @@ -40986,11 +40988,17 @@ will add the following content to the @file{setup-environment} script (which is expected to be sourced by the login shell): @example -export LESSHISTFILE=$XDG_CACHE_HOME/.lesshst -export SHELL=/gnu/store/2hsg15n644f0glrcbkb1kqknmmqdar03-zsh-5.8/bin/zsh +export LESSHISTFILE="$XDG_CACHE_HOME/.lesshst" +export SHELL="/gnu/store/2hsg15n644f0glrcbkb1kqknmmqdar03-zsh-5.8/bin/zsh" export _JAVA_AWT_WM_NONREPARENTING +export LITERAL_VALUE='$@{abc@}' @end example +Notice that @code{literal-string} above lets us declare that a value is +to be interpreted as a @dfn{literal string}, meaning that ``special +characters'' such as the dollar sign will not be interpreted by the +shell. + @quotation Note Make sure that module @code{(gnu packages shells)} is imported with @code{use-modules} or any other way, this namespace contains the diff --git a/gnu/home/services.scm b/gnu/home/services.scm index 99035686f1..2c1f58fddf 100644 --- a/gnu/home/services.scm +++ b/gnu/home/services.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2021 Andrew Tropin ;;; Copyright © 2021 Xinglu Chen +;;; Copyright © 2022 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; @@ -33,6 +34,7 @@ (define-module (gnu home services) #:use-module (guix i18n) #:use-module (guix modules) #:use-module (srfi srfi-1) + #:use-module (srfi srfi-9) #:use-module (ice-9 match) #:use-module (ice-9 vlist) @@ -47,6 +49,10 @@ (define-module (gnu home services) home-run-on-change-service-type home-provenance-service-type + literal-string + literal-string? + literal-string-value + environment-variable-shell-definitions home-files-directory xdg-configuration-files-directory @@ -171,32 +177,50 @@ (define home-profile-service-type configuration files that the user has declared in their @code{home-environment} record."))) +;; Representation of a literal string. +(define-record-type + (literal-string str) + literal-string? + (str literal-string-value)) + (define (environment-variable-shell-definitions variables) "Return a gexp that evaluates to a list of POSIX shell statements defining VARIABLES, a list of environment variable name/value pairs. The returned code ensures variable values are properly quoted." - #~(let ((shell-quote - (lambda (value) - ;; Double-quote VALUE, leaving dollar sign as is. - (let ((quoted (list->string - (string-fold-right + #~(let* ((quote-string + (lambda (value quoted-chars) + (list->string (string-fold-right (lambda (chr lst) - (case chr - ((#\" #\\) - (append (list chr #\\) lst)) - (else (cons chr lst)))) + (if (memq chr quoted-chars) + (append (list chr #\\) lst) + (cons chr lst))) '() value)))) - (string-append "\"" quoted "\""))))) + (shell-double-quote + (lambda (value) + ;; Double-quote VALUE, leaving dollar sign as is. + (string-append "\"" (quote-string value '(#\" #\\)) + "\""))) + (shell-single-quote + (lambda (value) + ;; Single-quote VALUE to enter a literal string. + (string-append "'" (quote-string value '(#\' #\\)) + "'")))) (string-append #$@(map (match-lambda ((key . #f) "") ((key . #t) #~(string-append "export " #$key "\n")) - ((key . value) + ((key . (? string? value)) #~(string-append "export " #$key "=" - (shell-quote #$value) "\n"))) + (shell-double-quote #$value) + "\n")) + ((key . (? literal-string? value)) + #~(string-append "export " #$key "=" + (shell-single-quote + #$(literal-string-value value)) + "\n"))) variables)))) (define (environment-variables->setup-environment-script vars) diff --git a/tests/guix-home.sh b/tests/guix-home.sh index d5e2dadbb5..423ebf6f33 100644 --- a/tests/guix-home.sh +++ b/tests/guix-home.sh @@ -81,7 +81,8 @@ trap 'chmod -Rf +w "$test_directory"; rm -rf "$test_directory"' EXIT (simple-service 'add-environment-variable home-environment-variables-service-type - '(("TODAY" . "26 messidor"))) + `(("TODAY" . "26 messidor") + ("LITERAL" . ,(literal-string "${abc}")))) (simple-service 'home-bash-service-extension-test home-bash-service-type @@ -149,6 +150,7 @@ EOF grep -q "the content of ~/.config/test.conf" "${HOME}/.config/test.conf" grep '^export PS1="\$GUIX_ENVIRONMENT λ "$' "${HOME}/.bash_profile" ( . "${HOME}/.guix-home/setup-environment"; test "$TODAY" = "26 messidor" ) + ( . "${HOME}/.guix-home/setup-environment"; test "$LITERAL" = '${abc}' ) # This one should still be here. grep "stay around" "$HOME/.config/random-file" base-commit: 9369c1ccf47d9bf6f2e28a9454c1c329a2044f19 -- 2.38.1 From unknown Thu Aug 21 12:12:05 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#60341] [PATCH Home] home: services: environment-variables: Add support for literal strings. Resent-From: Andrew Tropin Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 27 Dec 2022 03:03:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60341 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Ludovic =?UTF-8?Q?Court=C3=A8s?= , 60341@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 60341-submit@debbugs.gnu.org id=B60341.167211016110686 (code B ref 60341); Tue, 27 Dec 2022 03:03:01 +0000 Received: (at 60341) by debbugs.gnu.org; 27 Dec 2022 03:02:41 +0000 Received: from localhost ([127.0.0.1]:54425 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pA0Ej-0002mH-4K for submit@debbugs.gnu.org; Mon, 26 Dec 2022 22:02:41 -0500 Received: from relay10.mail.gandi.net ([217.70.178.230]:53273) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pA0Ef-0002lz-1j for 60341@debbugs.gnu.org; Mon, 26 Dec 2022 22:02:39 -0500 Received: (Authenticated sender: andrew@trop.in) by mail.gandi.net (Postfix) with ESMTPSA id 148D424000A; Tue, 27 Dec 2022 03:02:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trop.in; s=gm1; t=1672110150; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=kfqr5fHaJDmDSGzyazU5tqXL+7jTDFNbwTdAw/+jkBg=; b=FSVKMoUTh+QkAI08y1Xojb2yNbDOkOv5M6/pZijB3WPqBNEvpWs5fzkaF0iOIJvi1h7Cjo f2HTkrAxDEQYZgehq2xXQvrC0aI+z9x3ary2tHMYXfDfJoMAUsI34/B/ZoyH58moxnkmk3 Rsky8JJh2XPbx+e43+NdZt0MDwcPXo860HCSqvQvCsFcrXUx2DeqcR7aRkZjd+WjGgNRqB XqH8b0tWRprIK4go+x0OBToyeprtWIRSheKXWr3Kotosr2vIWTmgMnZK66qwNasC8PceWL qWMuWKiQq8ebPLigVzn/VVIB/H+tY+E/NVTtNVIRV8zqLMQ78g3ZYHc7fRtSuA== From: Andrew Tropin In-Reply-To: <20221226181938.30003-1-ludo@gnu.org> References: <20221226181938.30003-1-ludo@gnu.org> Date: Tue, 27 Dec 2022 07:02:23 +0400 Message-ID: <87o7rpa6rk.fsf@trop.in> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" 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 (-) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 2022-12-26 19:19, Ludovic Court=C3=A8s wrote: > * gnu/home/services.scm (): New record type. > (environment-variable-shell-definitions): Split 'shell-quote' into > 'quote-string' and 'shell-double-quote'. Add 'shell-single-quote'. > Add clause for 'literal-string' records. > * tests/guix-home.sh: Test it. > * doc/guix.texi (Essential Home Services): Document it. > --- > doc/guix.texi | 14 ++++++++++--- > gnu/home/services.scm | 48 ++++++++++++++++++++++++++++++++----------- > tests/guix-home.sh | 4 +++- > 3 files changed, 50 insertions(+), 16 deletions(-) > > Hi! > > I found that it=E2=80=99s occasionally useful to be able to define shell = variables > with a value that is to be taken literally, without shell expansion. This > is what this patch implements. > > Thoughts? Hi Ludo, the code looks good. I'm a little conserned that one need to learn a new abstraction to properly quote the expression instead of just using " or ' inside value string, but we already have af4c103595a725194318f40fc5aba110772ff417 and with the current state of the code this change looks rational and idiomatic. Also, it makes the interface more high-level, which can be good in some circumstances. > > Ludo=E2=80=99. > > diff --git a/doc/guix.texi b/doc/guix.texi > index efd281d9b0..44361b481a 100644 > --- a/doc/guix.texi > +++ b/doc/guix.texi > @@ -40972,13 +40972,15 @@ The easiest way to extend a service type, witho= ut defining a new service > type is to use the @code{simple-service} helper from @code{(gnu > services)}. >=20=20 > +@findex literal-string > @lisp > (simple-service 'some-useful-env-vars-service > home-environment-variables-service-type > `(("LESSHISTFILE" . "$XDG_CACHE_HOME/.lesshst") > ("SHELL" . ,(file-append zsh "/bin/zsh")) > ("USELESS_VAR" . #f) > - ("_JAVA_AWT_WM_NONREPARENTING" . #t))) > + ("_JAVA_AWT_WM_NONREPARENTING" . #t) > + ("LITERAL_VALUE" . ,(literal-string "$@{abc@}")))) > @end lisp >=20=20 > If you include such a service in you home environment definition, it > @@ -40986,11 +40988,17 @@ will add the following content to the @file{set= up-environment} script > (which is expected to be sourced by the login shell): >=20=20 > @example > -export LESSHISTFILE=3D$XDG_CACHE_HOME/.lesshst > -export SHELL=3D/gnu/store/2hsg15n644f0glrcbkb1kqknmmqdar03-zsh-5.8/bin/z= sh > +export LESSHISTFILE=3D"$XDG_CACHE_HOME/.lesshst" > +export SHELL=3D"/gnu/store/2hsg15n644f0glrcbkb1kqknmmqdar03-zsh-5.8/bin/= zsh" > export _JAVA_AWT_WM_NONREPARENTING > +export LITERAL_VALUE=3D'$@{abc@}' > @end example >=20=20 > +Notice that @code{literal-string} above lets us declare that a value is > +to be interpreted as a @dfn{literal string}, meaning that ``special > +characters'' such as the dollar sign will not be interpreted by the > +shell. > + > @quotation Note > Make sure that module @code{(gnu packages shells)} is imported with > @code{use-modules} or any other way, this namespace contains the > diff --git a/gnu/home/services.scm b/gnu/home/services.scm > index 99035686f1..2c1f58fddf 100644 > --- a/gnu/home/services.scm > +++ b/gnu/home/services.scm > @@ -1,6 +1,7 @@ > ;;; GNU Guix --- Functional package management for GNU > ;;; Copyright =C2=A9 2021 Andrew Tropin > ;;; Copyright =C2=A9 2021 Xinglu Chen > +;;; Copyright =C2=A9 2022 Ludovic Court=C3=A8s > ;;; > ;;; This file is part of GNU Guix. > ;;; > @@ -33,6 +34,7 @@ (define-module (gnu home services) > #:use-module (guix i18n) > #:use-module (guix modules) > #:use-module (srfi srfi-1) > + #:use-module (srfi srfi-9) > #:use-module (ice-9 match) > #:use-module (ice-9 vlist) >=20=20 > @@ -47,6 +49,10 @@ (define-module (gnu home services) > home-run-on-change-service-type > home-provenance-service-type >=20=20 > + literal-string > + literal-string? > + literal-string-value > + > environment-variable-shell-definitions > home-files-directory > xdg-configuration-files-directory > @@ -171,32 +177,50 @@ (define home-profile-service-type > configuration files that the user has declared in their > @code{home-environment} record."))) >=20=20 > +;; Representation of a literal string. > +(define-record-type > + (literal-string str) > + literal-string? > + (str literal-string-value)) > + > (define (environment-variable-shell-definitions variables) > "Return a gexp that evaluates to a list of POSIX shell statements defi= ning > VARIABLES, a list of environment variable name/value pairs. The returne= d code > ensures variable values are properly quoted." > - #~(let ((shell-quote > - (lambda (value) > - ;; Double-quote VALUE, leaving dollar sign as is. > - (let ((quoted (list->string > - (string-fold-right > + #~(let* ((quote-string > + (lambda (value quoted-chars) > + (list->string (string-fold-right > (lambda (chr lst) > - (case chr > - ((#\" #\\) > - (append (list chr #\\) lst)) > - (else (cons chr lst)))) > + (if (memq chr quoted-chars) > + (append (list chr #\\) lst) > + (cons chr lst))) > '() > value)))) > - (string-append "\"" quoted "\""))))) > + (shell-double-quote > + (lambda (value) > + ;; Double-quote VALUE, leaving dollar sign as is. > + (string-append "\"" (quote-string value '(#\" #\\)) > + "\""))) > + (shell-single-quote > + (lambda (value) > + ;; Single-quote VALUE to enter a literal string. > + (string-append "'" (quote-string value '(#\' #\\)) > + "'")))) > (string-append > #$@(map (match-lambda > ((key . #f) > "") > ((key . #t) > #~(string-append "export " #$key "\n")) > - ((key . value) > + ((key . (? string? value)) > #~(string-append "export " #$key "=3D" > - (shell-quote #$value) "\n"))) > + (shell-double-quote #$value) > + "\n")) > + ((key . (? literal-string? value)) > + #~(string-append "export " #$key "=3D" > + (shell-single-quote > + #$(literal-string-value value)) > + "\n"))) > variables)))) >=20=20 > (define (environment-variables->setup-environment-script vars) > diff --git a/tests/guix-home.sh b/tests/guix-home.sh > index d5e2dadbb5..423ebf6f33 100644 > --- a/tests/guix-home.sh > +++ b/tests/guix-home.sh > @@ -81,7 +81,8 @@ trap 'chmod -Rf +w "$test_directory"; rm -rf "$test_dir= ectory"' EXIT >=20=20 > (simple-service 'add-environment-variable > home-environment-variables-service-type > - '(("TODAY" . "26 messidor"))) > + `(("TODAY" . "26 messidor") > + ("LITERAL" . ,(literal-string "${abc}")))) >=20=20 > (simple-service 'home-bash-service-extension-test > home-bash-service-type > @@ -149,6 +150,7 @@ EOF > grep -q "the content of ~/.config/test.conf" "${HOME}/.config/test.c= onf" > grep '^export PS1=3D"\$GUIX_ENVIRONMENT =CE=BB "$' "${HOME}/.bash_pr= ofile" > ( . "${HOME}/.guix-home/setup-environment"; test "$TODAY" =3D "26 me= ssidor" ) > + ( . "${HOME}/.guix-home/setup-environment"; test "$LITERAL" =3D '${a= bc}' ) >=20=20 > # This one should still be here. > grep "stay around" "$HOME/.config/random-file" > > base-commit: 9369c1ccf47d9bf6f2e28a9454c1c329a2044f19 =2D-=20 Best regards, Andrew Tropin --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEKEGaxlA4dEDH6S/6IgjSCVjB3rAFAmOqYEAACgkQIgjSCVjB 3rB92g//fS9bqqHpP4ir7JRQqe6s6VcepQF/IKlJ17cWUz5XqnUDn0pL68bR//kv W1k+YuTypleEkTFZRG/ZZCTlwVDRc4e6CujbrJypmghD7MSyjsLgVUr9PNsysQ2m Kd6EUP+/jbYvR3Mfo9AT9nTWn3UFvX13Y2XHdHHGBSaNgGvrKlwz7myg0RJcC6EI t6lz+H43y6IZeaDZ2LYEc4Wg5lM2KwU5Jcc0TCQ28KCVrjMjkMcd0gZvtEleHny6 mqydf2EujOabmNix0J7GXezRVDEOWNPlnBgCjYVMdq7DczYnRJUly8CfTOWprc0F UT20yicG0tp+3hVcabdF0a16rL2TgzNrDU48s/2awrctUyDm1PbkyzNvzirwwMpT s/ylsIM5kn3Wo/Kv5v3SVvT23IFuSUOylrfKX7XSPIqoBkucvNR0TskYJgglSEjs 4K5YsmLPoGsxMSkIDNcJPkOmVqoEhyiPLhRLTEzv9khbMRyADSDU4CnpNv4iKqNZ Z0QwhButIHJv4Q9SXPIX/TdOfbr22HfeB6cbcUdF3YkCKFwYf8YcLIXpjJ+sW9It qhN8TvkjfZHCSIPHDaZV73j7lzRzKkjUPQXiPHkKzgoHcZL8d5JRl8hF5LqfPd/q siSZ45hcWtACH+YeBtsHcT9QwKncA6agbCnJ9EOZRY/5V7BYDt4= =ikw6 -----END PGP SIGNATURE----- --=-=-=-- From unknown Thu Aug 21 12:12:05 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#60341] [PATCH Home] home: services: environment-variables: Add support for literal strings. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 03 Jan 2023 22:53:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60341 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Andrew Tropin Cc: 60341@debbugs.gnu.org Received: via spool by 60341-submit@debbugs.gnu.org id=B60341.167278637718480 (code B ref 60341); Tue, 03 Jan 2023 22:53:01 +0000 Received: (at 60341) by debbugs.gnu.org; 3 Jan 2023 22:52:57 +0000 Received: from localhost ([127.0.0.1]:47052 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pCq9Q-0004o0-Rm for submit@debbugs.gnu.org; Tue, 03 Jan 2023 17:52:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57124) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pCq9O-0004nj-4B for 60341@debbugs.gnu.org; Tue, 03 Jan 2023 17:52:55 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pCq9H-0003qJ-4u; Tue, 03 Jan 2023 17:52:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:In-Reply-To:Date:References:Subject:To: From; bh=IZMM4Xb7P6wIn5tB1YHUqy8icHNQaCglePEdTrHL4Xc=; b=GViRdVZfXYCH5UmEfTQ9 MzIm5DaoDQuQgXFUq5vVxfGIZ/fLfFDU7sATTFtgAMgCN7M6bMEXrfeASr/IdE3MYDdbfsqi9As41 FHnm/fnB1mA0p+LoVC/MOONEe5B8vWubD+HHdu8pqwxgYV9WzgHQaiaPYAmkj24dwOkDAWFKR/cT0 W6QXsQ9TcBwXnoSHmIhR92u1IvCdeFjOE6Sr/b2so7kSv2QADtA2Xb0WZVlk7tlBr63a/XDvHVEi5 W86sy7szTNofgpo6Mf6mJKkjSIz+JgDMkLi5N2Cxc9sSkjIxKPZ5K+AMOH9dPp+1Lm5MSexVyAzUd 8LKKzZqZV4iPIA==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201] helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pCq9G-00077i-P6; Tue, 03 Jan 2023 17:52:46 -0500 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= References: <20221226181938.30003-1-ludo@gnu.org> <87o7rpa6rk.fsf@trop.in> Date: Tue, 03 Jan 2023 23:52:44 +0100 In-Reply-To: <87o7rpa6rk.fsf@trop.in> (Andrew Tropin's message of "Tue, 27 Dec 2022 07:02:23 +0400") Message-ID: <871qob6xj7.fsf_-_@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.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, Andrew Tropin skribis: > On 2022-12-26 19:19, Ludovic Court=C3=A8s wrote: [...] >> I found that it=E2=80=99s occasionally useful to be able to define shell= variables >> with a value that is to be taken literally, without shell expansion. Th= is >> is what this patch implements. >> >> Thoughts? > > Hi Ludo, > > the code looks good. > > I'm a little conserned that one need to learn a new abstraction to > properly quote the expression instead of just using " or ' inside value > string, but we already have af4c103595a725194318f40fc5aba110772ff417 and > with the current state of the code this change looks rational and > idiomatic. Also, it makes the interface more high-level, which can be > good in some circumstances. Yeah, the shell/Scheme mixture is a bit weird; it=E2=80=99s sort of in-betw= een because you can=E2=80=99t completely ignore that it=E2=80=99s shell code un= der the hood. Looking at , I think we should strive to not generate non-working shell snippets. Automatic quoting and this =E2=80=98literal-string=E2=80=99 construct are a way to achieve that. Ludo=E2=80=99. From unknown Thu Aug 21 12:12:05 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#60341] [PATCH Home] home: services: environment-variables: Add support for literal strings. Resent-From: Andrew Tropin Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 04 Jan 2023 05:26:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60341 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: 60341@debbugs.gnu.org Received: via spool by 60341-submit@debbugs.gnu.org id=B60341.16728099091967 (code B ref 60341); Wed, 04 Jan 2023 05:26:01 +0000 Received: (at 60341) by debbugs.gnu.org; 4 Jan 2023 05:25:09 +0000 Received: from localhost ([127.0.0.1]:47308 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pCwGz-0000Vf-0w for submit@debbugs.gnu.org; Wed, 04 Jan 2023 00:25:09 -0500 Received: from relay3-d.mail.gandi.net ([217.70.183.195]:50233) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pCwGv-0000V4-OM for 60341@debbugs.gnu.org; Wed, 04 Jan 2023 00:25:07 -0500 Received: (Authenticated sender: andrew@trop.in) by mail.gandi.net (Postfix) with ESMTPSA id E4BB860005; Wed, 4 Jan 2023 05:24:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trop.in; s=gm1; t=1672809899; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=pY0oCrK69kqhHBfNg/cRJ1TEJC+INQYaALc5lz+HDwg=; b=Ox8ZOgIeXanibNt2Sv3RpRtoHj887yh1UO3KoypvF7cI1e0an3OJO3GZZUIZ8PJw4DPaU0 6+gVk6QjZVefNJ2jehMkn2FIS9lovAGOreWMLssXpsOjQT69qnugxzhkwoviYamEV8UQuG ycmYLI0TIhO9G2YRTCMAo6ikr/pZmvp+unRIXsnglMz2Bfqj4ueei8RT9U+Bh+e22HWxTB 67rezwBdDb6Xgt/SZjGW61P0xO7Ip7RdCmIO+AgniQ8CJQsPytqRmqkGJb6gK0eHn/9FHp Gs/UPhRiX9x3yAKZye7+wlBuWdZFRH+4n3+DLopYP1fvLb8Gob5fH1MsKwqePQ== From: Andrew Tropin In-Reply-To: <871qob6xj7.fsf_-_@gnu.org> References: <20221226181938.30003-1-ludo@gnu.org> <87o7rpa6rk.fsf@trop.in> <871qob6xj7.fsf_-_@gnu.org> Date: Wed, 04 Jan 2023 09:24:55 +0400 Message-ID: <874jt6c1nc.fsf@trop.in> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" 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 (-) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 2023-01-03 23:52, Ludovic Court=C3=A8s wrote: > Hi, > > Andrew Tropin skribis: > >> On 2022-12-26 19:19, Ludovic Court=C3=A8s wrote: > > [...] > >>> I found that it=E2=80=99s occasionally useful to be able to define shel= l variables >>> with a value that is to be taken literally, without shell expansion. T= his >>> is what this patch implements. >>> >>> Thoughts? >> >> Hi Ludo, >> >> the code looks good. >> >> I'm a little conserned that one need to learn a new abstraction to >> properly quote the expression instead of just using " or ' inside value >> string, but we already have af4c103595a725194318f40fc5aba110772ff417 and >> with the current state of the code this change looks rational and >> idiomatic. Also, it makes the interface more high-level, which can be >> good in some circumstances. > > Yeah, the shell/Scheme mixture is a bit weird; it=E2=80=99s sort of in-be= tween > because you can=E2=80=99t completely ignore that it=E2=80=99s shell code = under the hood. > > Looking at , I think we should strive > to not generate non-working shell snippets. Automatic quoting and this > =E2=80=98literal-string=E2=80=99 construct are a way to achieve that. Yep, I think this is a way to go. =2D-=20 Best regards, Andrew Tropin --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEKEGaxlA4dEDH6S/6IgjSCVjB3rAFAmO1DacACgkQIgjSCVjB 3rAtaA/+OyZlFHlMBE/anUfmGxS+nbwAA+DbnS4iZF0d4cOPBEbKE0fXF+mg8sxG cicet9x8W3H5PY7017sku1PczQ0Z/EYmrEkN1vMXxCLtZwGWzGW20w1fV0QFBUuU yedFt9YhO/v81BvX5B+nT6ySJXQgmvkEGlB4nE9+k7zc5mN+0SedXnXLz7+7yeJr OL4OCoxLRzaeR+7Wk2pVtNBg06RftCWcFED7MQCSLFpwskVRhcZy+JDssWBGGaXc Wh6ANnKxiN14UGT6L2bslKMCubanfTXcfccZeL4KKMt2V+B4fvTTiAsAmSecvagg pAoxaXwm0s6S7Wqpd+YkWoWHfzItrDMFWdmQlcMrJ/fiSz2cucgF7feQD4m8v0HC w6LCkyu93enHpLBoLOIVBjNvu214rxc43DODKAJzjfil5JttIm0SfUwtK7Zw/Rs9 90jBdZu8c1LycxUqLKUTqWRoDpsw66wKK4cFGAiOpMs5moFN66idrW4tBtQe/WiE 6xtaghFs4z0LkM+A+FCLKLUNZboOvxQUKagLQ8sB0OOoehhi/OwqWlfc1XAmhTk1 0YF1KK3C6kF5bWiGikPN+8/VxWz52JF6GrS5cvcanZVFRJTaxr9LmmhWt3LnDBD8 FJ6JX7BSBKUHNrkD5ICMyDdlnytTRrMCxPYM5arSTBZIHUrEP1g= =GoBM -----END PGP SIGNATURE----- --=-=-=-- From unknown Thu Aug 21 12:12:05 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#60341: closed (Re: bug#60341: [PATCH Home] home: services: environment-variables: Add support for literal strings.) Message-ID: References: <87zgax2hfi.fsf_-_@gnu.org> <20221226181938.30003-1-ludo@gnu.org> X-Gnu-PR-Message: they-closed 60341 X-Gnu-PR-Package: guix-patches X-Gnu-PR-Keywords: patch Reply-To: 60341@debbugs.gnu.org Date: Thu, 05 Jan 2023 14:20:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1672928402-31674-1" This is a multi-part message in MIME format... ------------=_1672928402-31674-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #60341: [PATCH Home] home: services: environment-variables: Add support for= literal strings. 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 60341@debbugs.gnu.org. --=20 60341: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D60341 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1672928402-31674-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 60341-done) by debbugs.gnu.org; 5 Jan 2023 14:19:04 +0000 Received: from localhost ([127.0.0.1]:50552 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pDR5D-0008DZ-Ns for submit@debbugs.gnu.org; Thu, 05 Jan 2023 09:19:03 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34910) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pDR5C-0008D6-3W for 60341-done@debbugs.gnu.org; Thu, 05 Jan 2023 09:19:02 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pDR56-0005I4-Ds; Thu, 05 Jan 2023 09:18:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:In-Reply-To:Date:References:Subject:To: From; bh=NhJwko1+S2wTbQa3z34PHV7KzI+rGBcXkfXgakyvdIE=; b=rlCdZ0HlhsJye1l2KUfU B+9r+c/MAm8kdokmuBi+aMySfrW3P9T9vOpjQdKJT9IjK2DP5AT5X+5YCkPNWtEvWsOlgpwQlYd6B dvv04tNcHXjnIC+CIhL66llcHRWwoiyG+xBerNgv0C9NvnhZe9AYWV+3ois8orhFRueVIys2gfOSS pvStBzXL/FlEvig3i/39QT33B3ILZ00242oDt8Ag4k8zPox7ZnN46ECHuFBxlB4xLxSOaNwCN/kVz QSCQpxLSlLJmNR4BbsuHeVJMkDtCBaD0z7z0cSqx4v6qgH7qJcsSKLZChh2Szw6bOGfbkhnacsv6J /QyG2DIG9wf00A==; Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pDR4s-000530-UQ; Thu, 05 Jan 2023 09:18:50 -0500 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Andrew Tropin Subject: Re: bug#60341: [PATCH Home] home: services: environment-variables: Add support for literal strings. References: <20221226181938.30003-1-ludo@gnu.org> <87o7rpa6rk.fsf@trop.in> <871qob6xj7.fsf_-_@gnu.org> <874jt6c1nc.fsf@trop.in> Date: Thu, 05 Jan 2023 15:18:41 +0100 In-Reply-To: <874jt6c1nc.fsf@trop.in> (Andrew Tropin's message of "Wed, 04 Jan 2023 09:24:55 +0400") Message-ID: <87zgax2hfi.fsf_-_@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.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: 60341-done Cc: 60341-done@debbugs.gnu.org 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 (---) Andrew Tropin skribis: > On 2023-01-03 23:52, Ludovic Court=C3=A8s wrote: [...] >> Yeah, the shell/Scheme mixture is a bit weird; it=E2=80=99s sort of in-b= etween >> because you can=E2=80=99t completely ignore that it=E2=80=99s shell code= under the hood. >> >> Looking at , I think we should strive >> to not generate non-working shell snippets. Automatic quoting and this >> =E2=80=98literal-string=E2=80=99 construct are a way to achieve that. > > Yep, I think this is a way to go. Alright, pushed as 73684dc90e013f2f0cca1097b0c944bb9aa88709. Thanks! Ludo=E2=80=99. ------------=_1672928402-31674-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 26 Dec 2022 18:20:03 +0000 Received: from localhost ([127.0.0.1]:54098 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p9s4w-00041s-LZ for submit@debbugs.gnu.org; Mon, 26 Dec 2022 13:20:03 -0500 Received: from lists.gnu.org ([209.51.188.17]:39598) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p9s4u-00041P-50 for submit@debbugs.gnu.org; Mon, 26 Dec 2022 13:20:01 -0500 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 1p9s4m-0005fx-CG for guix-patches@gnu.org; Mon, 26 Dec 2022 13:19:52 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p9s4j-0005fs-Ih; Mon, 26 Dec 2022 13:19:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=w16Xa9XGXEA31PBhkbHgKl9B6mn/HRUFLEYGIdf8cuo=; b=e4Tb0rSj7k6KJG PCazL8Z3Ks0LcuzLxDFz2sIURMxRXLPX4k4xd/uGCjE4SlteZGcrqS4RSPR6j7JY7VB5yVT5VdXf3 t4MkF92kP6n+y6BLzqD+nZRpk//1rgRJbV3qg2rR8qPbWyottSONw7W2JoLtz4E+TTyyQr4VntexT a1b9/jg7TIEtXaMIh8YYFtOMxCnUP2j6Pp7Aqsd9QrOAf3elRSeMpGQL8024P1c990c8pI1a9ZpXk 2jDalD14z2S4Q+cXRlWMK6YsFQNOxq58XWBtfJ/oxevzKl/3wCbrUTqVYwq130rG4nGYbcV+Mgiv/ x+G2GI5ho0o7RjrrM/mA==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201] 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 1p9s4h-0007Fq-RZ; Mon, 26 Dec 2022 13:19:48 -0500 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= To: guix-patches@gnu.org Subject: [PATCH Home] home: services: environment-variables: Add support for literal strings. Date: Mon, 26 Dec 2022 19:19:38 +0100 Message-Id: <20221226181938.30003-1-ludo@gnu.org> X-Mailer: git-send-email 2.38.1 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 (---) * gnu/home/services.scm (): New record type. (environment-variable-shell-definitions): Split 'shell-quote' into 'quote-string' and 'shell-double-quote'. Add 'shell-single-quote'. Add clause for 'literal-string' records. * tests/guix-home.sh: Test it. * doc/guix.texi (Essential Home Services): Document it. --- doc/guix.texi | 14 ++++++++++--- gnu/home/services.scm | 48 ++++++++++++++++++++++++++++++++----------- tests/guix-home.sh | 4 +++- 3 files changed, 50 insertions(+), 16 deletions(-) Hi! I found that it’s occasionally useful to be able to define shell variables with a value that is to be taken literally, without shell expansion. This is what this patch implements. Thoughts? Ludo’. diff --git a/doc/guix.texi b/doc/guix.texi index efd281d9b0..44361b481a 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -40972,13 +40972,15 @@ The easiest way to extend a service type, without defining a new service type is to use the @code{simple-service} helper from @code{(gnu services)}. +@findex literal-string @lisp (simple-service 'some-useful-env-vars-service home-environment-variables-service-type `(("LESSHISTFILE" . "$XDG_CACHE_HOME/.lesshst") ("SHELL" . ,(file-append zsh "/bin/zsh")) ("USELESS_VAR" . #f) - ("_JAVA_AWT_WM_NONREPARENTING" . #t))) + ("_JAVA_AWT_WM_NONREPARENTING" . #t) + ("LITERAL_VALUE" . ,(literal-string "$@{abc@}")))) @end lisp If you include such a service in you home environment definition, it @@ -40986,11 +40988,17 @@ will add the following content to the @file{setup-environment} script (which is expected to be sourced by the login shell): @example -export LESSHISTFILE=$XDG_CACHE_HOME/.lesshst -export SHELL=/gnu/store/2hsg15n644f0glrcbkb1kqknmmqdar03-zsh-5.8/bin/zsh +export LESSHISTFILE="$XDG_CACHE_HOME/.lesshst" +export SHELL="/gnu/store/2hsg15n644f0glrcbkb1kqknmmqdar03-zsh-5.8/bin/zsh" export _JAVA_AWT_WM_NONREPARENTING +export LITERAL_VALUE='$@{abc@}' @end example +Notice that @code{literal-string} above lets us declare that a value is +to be interpreted as a @dfn{literal string}, meaning that ``special +characters'' such as the dollar sign will not be interpreted by the +shell. + @quotation Note Make sure that module @code{(gnu packages shells)} is imported with @code{use-modules} or any other way, this namespace contains the diff --git a/gnu/home/services.scm b/gnu/home/services.scm index 99035686f1..2c1f58fddf 100644 --- a/gnu/home/services.scm +++ b/gnu/home/services.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2021 Andrew Tropin ;;; Copyright © 2021 Xinglu Chen +;;; Copyright © 2022 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; @@ -33,6 +34,7 @@ (define-module (gnu home services) #:use-module (guix i18n) #:use-module (guix modules) #:use-module (srfi srfi-1) + #:use-module (srfi srfi-9) #:use-module (ice-9 match) #:use-module (ice-9 vlist) @@ -47,6 +49,10 @@ (define-module (gnu home services) home-run-on-change-service-type home-provenance-service-type + literal-string + literal-string? + literal-string-value + environment-variable-shell-definitions home-files-directory xdg-configuration-files-directory @@ -171,32 +177,50 @@ (define home-profile-service-type configuration files that the user has declared in their @code{home-environment} record."))) +;; Representation of a literal string. +(define-record-type + (literal-string str) + literal-string? + (str literal-string-value)) + (define (environment-variable-shell-definitions variables) "Return a gexp that evaluates to a list of POSIX shell statements defining VARIABLES, a list of environment variable name/value pairs. The returned code ensures variable values are properly quoted." - #~(let ((shell-quote - (lambda (value) - ;; Double-quote VALUE, leaving dollar sign as is. - (let ((quoted (list->string - (string-fold-right + #~(let* ((quote-string + (lambda (value quoted-chars) + (list->string (string-fold-right (lambda (chr lst) - (case chr - ((#\" #\\) - (append (list chr #\\) lst)) - (else (cons chr lst)))) + (if (memq chr quoted-chars) + (append (list chr #\\) lst) + (cons chr lst))) '() value)))) - (string-append "\"" quoted "\""))))) + (shell-double-quote + (lambda (value) + ;; Double-quote VALUE, leaving dollar sign as is. + (string-append "\"" (quote-string value '(#\" #\\)) + "\""))) + (shell-single-quote + (lambda (value) + ;; Single-quote VALUE to enter a literal string. + (string-append "'" (quote-string value '(#\' #\\)) + "'")))) (string-append #$@(map (match-lambda ((key . #f) "") ((key . #t) #~(string-append "export " #$key "\n")) - ((key . value) + ((key . (? string? value)) #~(string-append "export " #$key "=" - (shell-quote #$value) "\n"))) + (shell-double-quote #$value) + "\n")) + ((key . (? literal-string? value)) + #~(string-append "export " #$key "=" + (shell-single-quote + #$(literal-string-value value)) + "\n"))) variables)))) (define (environment-variables->setup-environment-script vars) diff --git a/tests/guix-home.sh b/tests/guix-home.sh index d5e2dadbb5..423ebf6f33 100644 --- a/tests/guix-home.sh +++ b/tests/guix-home.sh @@ -81,7 +81,8 @@ trap 'chmod -Rf +w "$test_directory"; rm -rf "$test_directory"' EXIT (simple-service 'add-environment-variable home-environment-variables-service-type - '(("TODAY" . "26 messidor"))) + `(("TODAY" . "26 messidor") + ("LITERAL" . ,(literal-string "${abc}")))) (simple-service 'home-bash-service-extension-test home-bash-service-type @@ -149,6 +150,7 @@ EOF grep -q "the content of ~/.config/test.conf" "${HOME}/.config/test.conf" grep '^export PS1="\$GUIX_ENVIRONMENT λ "$' "${HOME}/.bash_profile" ( . "${HOME}/.guix-home/setup-environment"; test "$TODAY" = "26 messidor" ) + ( . "${HOME}/.guix-home/setup-environment"; test "$LITERAL" = '${abc}' ) # This one should still be here. grep "stay around" "$HOME/.config/random-file" base-commit: 9369c1ccf47d9bf6f2e28a9454c1c329a2044f19 -- 2.38.1 ------------=_1672928402-31674-1-- From unknown Thu Aug 21 12:12:05 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#60341] Thanks References: <20221226181938.30003-1-ludo@gnu.org> In-Reply-To: <20221226181938.30003-1-ludo@gnu.org> Resent-From: Trev Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 08 Jan 2023 02:30:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60341 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 60341@debbugs.gnu.org Received: via spool by 60341-submit@debbugs.gnu.org id=B60341.167314499828270 (code B ref 60341); Sun, 08 Jan 2023 02:30:02 +0000 Received: (at 60341) by debbugs.gnu.org; 8 Jan 2023 02:29:58 +0000 Received: from localhost ([127.0.0.1]:59475 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pELRP-0007Le-DG for submit@debbugs.gnu.org; Sat, 07 Jan 2023 21:29:58 -0500 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:39387) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pELRN-0007LP-GQ for 60341@debbugs.gnu.org; Sat, 07 Jan 2023 21:29:42 -0500 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 44BF05C00B0 for <60341@debbugs.gnu.org>; Sat, 7 Jan 2023 21:29:34 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Sat, 07 Jan 2023 21:29:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trevdev.ca; h=cc :content-type:date:date:from:from:in-reply-to:message-id :mime-version:reply-to:sender:subject:subject:to:to; s=fm3; t= 1673144974; x=1673231374; bh=I/8Ugo056GIqxz0E1qEl4djZlTlivbiBAjd Iv2hVXkk=; b=FZnp6OIUca6g7GPKC23KNP4p00yGoHGau4VUJwitZVmx2jAczhW 53VQP4vIUFmfW1JrNdazjn4zS7prP1eq3ptDF3PENGwvrLxl1dgfdkq9XzAREVBz Qa7nxVVLgdOuf59XzVgXw9SwP7hRbIAG5EnyzgNXyBn9rbx81Rzxg89SijVCvoa8 eWzzb8SImRIyZX1QOxMzKrtSSPG28eiVnUfQZlt6IWB45ePF4asRuBHu69yrPBkG nSEEE0tCRKK83NLBkbMcIA/x7vh5c8z78l7FunSQ+ia2s7r5UgQ0LfOKT7+txmMN +4LOmwX1KLsFG2h+iryM2EmWi0HvdHoJySw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:message-id:mime-version :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1673144974; x= 1673231374; bh=I/8Ugo056GIqxz0E1qEl4djZlTlivbiBAjdIv2hVXkk=; b=r i83iCQ+qG/PkfCCqKcCWrxDHTrYXs5vTnx8eIRRJnZMh3u5IDesa9JdtzOo9Q1AJ h6I517si6H7QnGNXejj/511fYGrdiPcmG/QsXQxp+BAsfD2us8SqdeNuvH05hYFX UtYYMaGh8onO9jK03wmA0uyzcJJDvPH/pnT0DkwqxdFTRc+nJRqyh7821ncpdGpL KJRlGwlAXdKetStRD/AjsbOYWOfZzZ+87YG7yBC1bZK9pCjqADLojl3VB5Z/KUmR rWSMYEMADA1lkwNZDe1d323bBeoxC96KVSsx8m6rsJb38UG7HKNrd+8hojGfCxH5 J2xr/w8+IYlQbyfrckCEQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrkeefgdegjecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfggtggusehttdertddttd ejnecuhfhrohhmpefvrhgvvhcuoehtrhgvvhesthhrvghvuggvvhdrtggrqeenucggtffr rghtthgvrhhnpeefiedvheevudefvdfftdefiefgkeefgefgkeetudeijeeivdejieffge ehgfekhfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhm pehtrhgvvhesthhrvghvuggvvhdrtggr X-ME-Proxy: Feedback-ID: i762946f9:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for <60341@debbugs.gnu.org>; Sat, 7 Jan 2023 21:29:33 -0500 (EST) Date: Sat, 7 Jan 2023 18:29:32 -0800 From: Trev Message-ID: <20230108022932.koiszub7tzifvwae@guix> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline 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.0 (-) I always knew my `environment-variables` were a mess. This patch broke my guix home config and send me down a confusing rabbit hole to this submission. My environment-variables form looks so nice now ;P -- Trev : 0FB7 D06B 4A2A F07E AD5B 1169 183B 6306 8AA1 D206