From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:306:2d92::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id cJ6lAL3XpmRblQAASxT56A (envelope-from ) for ; Thu, 06 Jul 2023 17:03:25 +0200 Received: from aspmx1.migadu.com ([2001:41d0:306:2d92::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id 2NM/AL3XpmQxaAEAauVa8A (envelope-from ) for ; Thu, 06 Jul 2023 17:03:25 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 3A68333951 for ; Thu, 6 Jul 2023 17:03:21 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=K8Ieb6BD; spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1688655804; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=KNA7O3emHPG7khztgLGFBu7nVJokFEa23Xmi0+F54Vg=; b=YLL47qQRcYcMtG1Quz+h0BQ4Kdxay8MLMSdoUKTfjDJodi7DCSyB1CBiz+fpG3812oiqWP UxbIptSkLJAqCJ3A89iguFCNDMjq36V1Nkm2laMu3KV3KMw/4O0MuKNpBYgiX805eLsn04 CghEqe9+9r2TfyDlnKstAKZR4UJCTyKI0wGNyRG4+8wIbjvzMCXByaV+udOZJiWrLmttYJ UBqCDHr46NywoZuPj1VhKbYfNnj6ibtnTXDhFsJcIWJ+ZJPv1t82JzB9uONZO7E5PM0i2k dtFE0+0Me0sEPFsYEDCQZ/2aVbZnqXtzzOvG657o5wlFk3yrR+hy0P9Ivo4vVQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1688655804; a=rsa-sha256; cv=none; b=akObMZBIMf74HY29EGiAUo4BjrjqBZTSJyxiR7IkQAaDv4NdJqmuU3QmTsDYxjw2Fn4V65 HbXAmDZR8stmvlD/sp1PpugzH5xBSr70XgdW2pQogiawSKgMZewFNEMCuzYmak1JM4aQy+ zjPgHERIZOodZdp+dtFnrkdle2QcwlLHL18FDA53GYC5TGLIdMvW9hGhb/zi6LjS0ykwa7 pSzQDDwmjRiZzkxuUpIq+MuGUfbCaTBrTt2/V70uoGa6e3syonEHtbVu+C7yHKBDXF1iZo H8x82ziY+O4Wk/fDBfECIGcF7Nn38BV6nI8XVAMHModRhtg8DxDah77/96hQ7w== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=K8Ieb6BD; spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHQVd-0004w2-Dv; Thu, 06 Jul 2023 11:03:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qHQVb-0004v5-Bx for bug-guix@gnu.org; Thu, 06 Jul 2023 11:03:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qHQVa-000459-77 for bug-guix@gnu.org; Thu, 06 Jul 2023 11:03:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qHQVa-0007sh-08 for bug-guix@gnu.org; Thu, 06 Jul 2023 11:03:02 -0400 X-Loop: help-debbugs@gnu.org Subject: bug#63048: [PATCH] home: services: bash: Properly quote shell aliases. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: , bug-guix@gnu.org Resent-Date: Thu, 06 Jul 2023 15:03:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63048 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: 63048@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= , Ekaitz Zarraga , ( , Andrew Tropin , Ludovic =?UTF-8?Q?Court=C3=A8s?= X-Debbugs-Original-Xcc: ( , Andrew Tropin , Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 63048-submit@debbugs.gnu.org id=B63048.168865574030242 (code B ref 63048); Thu, 06 Jul 2023 15:03:01 +0000 Received: (at 63048) by debbugs.gnu.org; 6 Jul 2023 15:02:20 +0000 Received: from localhost ([127.0.0.1]:41840 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qHQUt-0007ri-O7 for submit@debbugs.gnu.org; Thu, 06 Jul 2023 11:02:20 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59498) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qHQUp-0007rQ-Ge for 63048@debbugs.gnu.org; Thu, 06 Jul 2023 11:02:18 -0400 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 1qHQUi-0003xf-C6; Thu, 06 Jul 2023 11:02:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=KNA7O3emHPG7khztgLGFBu7nVJokFEa23Xmi0+F54Vg=; b=K8Ieb6BDn1wRzXnDE+B8 +WKG1Vhl3gEAe16hFTGtMyZywGUXXXHBcb7LafEoKGJo/kjy52P8HQuWxyno75dLYcKQ3xvZ2pY9l E+kHovQV/rG2R3q0YLKRub+Cc3uVufqaKsWTbmE+Nfur88eh2yIrbwyTWM+gK/70FBqas56orEIdB ecQxfNHmx32c5M19A+Ke8KbuYZt7NFBB4CSrC6QhxQI2f/+VuasqsmJDtND4vnKuUnVpy6XRrXMpu RkcKNOetUXnWCkql6tX/xDNFFAkZX4g/FEVb3MJehUBKVesev5B3jRQeo7whZ9m2Rc13oUUGfXWkH hHMmu5bXKlTJaw==; Received: from [193.50.110.205] (helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qHQUh-0001Ku-St; Thu, 06 Jul 2023 11:02:08 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Thu, 6 Jul 2023 17:01:54 +0200 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guix@gnu.org List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+larch=yhetil.org@gnu.org Sender: bug-guix-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -1.67 X-Spam-Score: -1.67 X-Migadu-Queue-Id: 3A68333951 X-Migadu-Scanner: mx2.migadu.com X-TUID: +qy+28x5mmxp From: Ludovic Courtès Fixes . Reported by Ekaitz Zarraga . * gnu/home/services.scm (with-shell-quotation-bindings): New procedure. (environment-variable-shell-definitions): Use it instead of inline copy. * gnu/home/services/shells.scm (bash-serialize-aliases): Use it. Add clause for 'literal-string?'. * tests/guix-home.sh: Add 'aliases' to 'home-bash-extension' and test it. --- gnu/home/services.scm | 53 ++++++++++++++++++++---------------- gnu/home/services/shells.scm | 28 ++++++++++++------- tests/guix-home.sh | 7 ++++- 3 files changed, 54 insertions(+), 34 deletions(-) Hi! Here's a patch that fixes it. AFAICS 'guix home import' does the right thing, so this is really just fixing the way aliases are serialized. Let me know what you think! Ludo'. diff --git a/gnu/home/services.scm b/gnu/home/services.scm index b17a34d19d..042eba4780 100644 --- a/gnu/home/services.scm +++ b/gnu/home/services.scm @@ -53,6 +53,7 @@ (define-module (gnu home services) literal-string? literal-string-value + with-shell-quotation-bindings environment-variable-shell-definitions home-files-directory xdg-configuration-files-directory @@ -183,11 +184,10 @@ (define-record-type 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* ((quote-string +(define (with-shell-quotation-bindings exp) + "Insert EXP, a gexp, in a lexical environment providing the +'shell-single-quote' and 'shell-double-quote' bindings." +#~(let* ((quote-string (lambda (value quoted-chars) (list->string (string-fold-right (lambda (chr lst) @@ -206,24 +206,31 @@ (define (environment-variable-shell-definitions variables) ;; 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 . (or (? string? value) - (? file-like? value) - (? gexp? value))) - #~(string-append "export " #$key "=" - (shell-double-quote #$value) - "\n")) - ((key . (? literal-string? value)) - #~(string-append "export " #$key "=" - (shell-single-quote - #$(literal-string-value value)) - "\n"))) - variables)))) + #$exp)) + +(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." + (with-shell-quotation-bindings + #~(string-append + #$@(map (match-lambda + ((key . #f) + "") + ((key . #t) + #~(string-append "export " #$key "\n")) + ((key . (or (? string? value) + (? file-like? value) + (? gexp? value))) + #~(string-append "export " #$key "=" + (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) "Return a file that can be sourced by a POSIX compliant shell which diff --git a/gnu/home/services/shells.scm b/gnu/home/services/shells.scm index 415b5470c5..7960590e7c 100644 --- a/gnu/home/services/shells.scm +++ b/gnu/home/services/shells.scm @@ -313,16 +313,24 @@ (define home-zsh-service-type ;;; (define (bash-serialize-aliases field-name val) - #~(string-append - #$@(map - (match-lambda - ((key . #f) - "") - ((key . #t) - #~(string-append "alias " #$key "\n")) - ((key . value) - #~(string-append "alias " #$key "=\"" #$value "\"\n"))) - val))) + (with-shell-quotation-bindings + #~(string-append + #$@(map + (match-lambda + ((key . #f) + "") + ((key . #t) + #~(string-append "alias " #$key "\n")) + ((key . (? literal-string? value)) + #~(string-append "alias " #$key "=" + (shell-single-quote + #$(literal-string-value value)) + "\n")) + ((key . value) + #~(string-append "alias " #$key "=" + (shell-double-quote #$value) + "\n"))) + val)))) (define-configuration home-bash-configuration (package diff --git a/tests/guix-home.sh b/tests/guix-home.sh index e9ef76c862..e6d16d7fab 100644 --- a/tests/guix-home.sh +++ b/tests/guix-home.sh @@ -1,7 +1,7 @@ # GNU Guix --- Functional package management for GNU # Copyright © 2021-2023 Andrew Tropin # Copyright © 2021 Oleg Pykhalov -# Copyright © 2022 Ludovic Courtès +# Copyright © 2022, 2023 Ludovic Courtès # # This file is part of GNU Guix. # @@ -94,6 +94,9 @@ trap 'chmod -Rf +w "$test_directory"; rm -rf "$test_directory"' EXIT (home-bash-extension (environment-variables '(("PS1" . "$GUIX_ENVIRONMENT λ "))) + (aliases + `(("run" . "guix shell") + ("path" . ,(literal-string "echo $PATH")))) (bashrc (list (plain-file @@ -149,6 +152,8 @@ EOF test -d "${HOME}/.guix-home" test -h "${HOME}/.bash_profile" test -h "${HOME}/.bashrc" + grep 'alias run="guix shell"' "$HOME/.bashrc" + grep "alias path='echo \$PATH'" "$HOME/.bashrc" test "$(tail -n 2 "${HOME}/.bashrc")" == "\ # dot-bashrc test file for guix home # the content of bashrc-test-config.sh" base-commit: 2426e51688d479042ea115a634c6be2d8b9f3b99 -- 2.40.1