From patchwork Mon Nov 1 09:45:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Xinglu Chen X-Patchwork-Id: 34196 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 0E6F227BBE3; Mon, 1 Nov 2021 09:46:11 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,T_DKIM_INVALID, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 943EF27BBE1 for ; Mon, 1 Nov 2021 09:46:10 +0000 (GMT) Received: from localhost ([::1]:56964 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mhTtJ-0000nP-M3 for patchwork@mira.cbaines.net; Mon, 01 Nov 2021 05:46:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52848) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mhTtC-0000kg-3l for guix-patches@gnu.org; Mon, 01 Nov 2021 05:46:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:50416) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mhTtB-00050S-RR for guix-patches@gnu.org; Mon, 01 Nov 2021 05:46:01 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mhTtB-0000Cm-Px for guix-patches@gnu.org; Mon, 01 Nov 2021 05:46:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#51543] [PATCH 1/2] home: services: bash: Add =?utf-8?b?4oCY?= =?utf-8?b?YWxpYXNlc+KAmQ==?= field. Resent-From: Xinglu Chen Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 01 Nov 2021 09:46:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51543 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 51543@debbugs.gnu.org Received: via spool by 51543-submit@debbugs.gnu.org id=B51543.1635759940753 (code B ref 51543); Mon, 01 Nov 2021 09:46:01 +0000 Received: (at 51543) by debbugs.gnu.org; 1 Nov 2021 09:45:40 +0000 Received: from localhost ([127.0.0.1]:33728 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mhTsp-0000C5-MI for submit@debbugs.gnu.org; Mon, 01 Nov 2021 05:45:40 -0400 Received: from h87-96-130-155.cust.a3fiber.se ([87.96.130.155]:57986 helo=mail.yoctocell.xyz) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mhTso-0000Br-8l for 51543@debbugs.gnu.org; Mon, 01 Nov 2021 05:45:38 -0400 From: Xinglu Chen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yoctocell.xyz; s=mail; t=1635759932; bh=7H+iBW9fJrRBVeHOMANQPr6F0L/UdGEzCmECI18VOMI=; h=From:To:Subject:In-Reply-To:References:Date; b=h8Gb93/vMmU/Ay/OaoulLRFBm7wMzpg7CF0tfD5EXVMJY1Am9wPfKb+erGkLoZJxc KL0nADxrftsBivbFxMeWF7PE3l425IkySZ2hLJmQW2p6dn7SrAjiokgKq28rBbS/ZL ciZNO1tLhzcJq4G+dev5tcB2gvZxLtA/w7gk2veQ= In-Reply-To: References: Message-Id: <231301123d2fe00e6c65e94ec45ffc906bf95ee1.1635759704.git.public@yoctocell.xyz> Date: Mon, 01 Nov 2021 10:45:32 +0100 MIME-Version: 1.0 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+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * doc/guix.texi (Shells Home Services): Document it. * gnu/home/services/shells.scm (bash-serialize-aliases): New procedure. (home-bash-configuration, home-bash-extension): Add ‘aliases’ field. (home-bash-extensions): Adjust accordingly. * guix/scripts/home/import.scm (generate-bash-configuration+modules): Populate the ‘alias’ field. --- doc/guix.texi | 14 ++++++ gnu/home/services/shells.scm | 85 ++++++++++++++++++++++++++---------- guix/scripts/home/import.scm | 24 ++++++++++ 3 files changed, 100 insertions(+), 23 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index ea1973f02c..f7312a5b30 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -36173,6 +36173,20 @@ @item @code{environment-variables} (default: @code{()}) (type: alist) Association list of environment variables to set for the Bash session. +@item @code{aliases} (default: @code{()}) (type: alist) +Association list of aliases to set for the Bash session. The alias will +automatically be quoted, so something line this: + +@lisp +'((\"ls\" . \"ls -alF\")) +@end lisp + +turns into + +@example +alias ls=\"ls -alF\" +@end example + @item @code{bash-profile} (default: @code{()}) (type: text-config) List of file-like objects, which will be added to @file{.bash_profile}. Used for executing user's commands at start of login shell (In most diff --git a/gnu/home/services/shells.scm b/gnu/home/services/shells.scm index e2730967b2..bd1595a041 100644 --- a/gnu/home/services/shells.scm +++ b/gnu/home/services/shells.scm @@ -305,6 +305,18 @@ (define home-zsh-service-type ;;; Bash. ;;; +(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))) + (define-configuration home-bash-configuration (package (package bash) @@ -317,6 +329,21 @@ (define-configuration home-bash-configuration (alist '()) "Association list of environment variables to set for the Bash session." serialize-posix-env-vars) + (aliases + (alist '()) + "Association list of aliases to set for the Bash session. The alias will +automatically be quoted, so something line this: + +@lisp +'((\"ls\" . \"ls -alF\")) +@end lisp + +turns into + +@example +alias ls=\"ls -alF\" +@end example" + bash-serialize-aliases) (bash-profile (text-config '()) "List of file-like objects, which will be added to @file{.bash_profile}. @@ -387,10 +414,11 @@ (define* (file-if-not-empty field #:optional (extra-content #f)) (if (or extra-content (not (null? ((configuration-field-getter field-obj) config)))) `(,(object->snake-case-string file-name) - ,(mixed-text-file + ,(apply mixed-text-file (object->snake-case-string file-name) - (if extra-content extra-content "") - (serialize-field field))) + (append + (if extra-content extra-content '()) + (list (serialize-field field))))) '()))) (filter @@ -413,8 +441,9 @@ (define* (file-if-not-empty field #:optional (extra-content #f)) ,@(list (file-if-not-empty 'bashrc (if (home-bash-configuration-guix-defaults? config) - guix-bashrc - #f)) + (list guix-bashrc + (serialize-field 'aliases)) + (list (serialize-field 'alises)))) (file-if-not-empty 'bash-logout))))) (define (add-bash-packages config) @@ -424,6 +453,9 @@ (define-configuration/no-serialization home-bash-extension (environment-variables (alist '()) "Association list of environment variables to set.") + (aliases + (alist '()) + "Association list of aliases to set.") (bash-profile (text-config '()) "List of file-like objects.") @@ -435,24 +467,31 @@ (define-configuration/no-serialization home-bash-extension "List of file-like objects.")) (define (home-bash-extensions original-config extension-configs) - (home-bash-configuration - (inherit original-config) - (environment-variables - (append (home-bash-configuration-environment-variables original-config) - (append-map - home-bash-extension-environment-variables extension-configs))) - (bash-profile - (append (home-bash-configuration-bash-profile original-config) - (append-map - home-bash-extension-bash-profile extension-configs))) - (bashrc - (append (home-bash-configuration-bashrc original-config) - (append-map - home-bash-extension-bashrc extension-configs))) - (bash-logout - (append (home-bash-configuration-bash-logout original-config) - (append-map - home-bash-extension-bash-logout extension-configs))))) + (match original-config + (($ _ _ _ environment-variables aliases + bash-profile bashrc bash-logout) + (home-bash-configuration + (inherit original-config) + (environment-variables + (append environment-variables + (append-map + home-bash-extension-environment-variables extension-configs))) + (aliases + (append aliases + (append-map + home-bash-extension-aliases extension-configs))) + (bash-profile + (append bash-profile + (append-map + home-bash-extension-bash-profile extension-configs))) + (bashrc + (append bashrc + (append-map + home-bash-extension-bashrc extension-configs))) + (bash-logout + (append bash-logout + (append-map + home-bash-extension-bash-logout extension-configs))))))) (define home-bash-service-type (service-type (name 'home-bash) diff --git a/guix/scripts/home/import.scm b/guix/scripts/home/import.scm index 7a7712dd96..68420ff7f9 100644 --- a/guix/scripts/home/import.scm +++ b/guix/scripts/home/import.scm @@ -27,6 +27,9 @@ (define-module (guix scripts home import) #:use-module (gnu packages) #:use-module (ice-9 match) #:use-module (ice-9 pretty-print) + #:use-module (ice-9 rdelim) + #:use-module (ice-9 regex) + #:use-module (ice-9 popen) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) #:export (import-manifest @@ -56,11 +59,32 @@ (define (generate-bash-configuration+modules destination-directory) (define (destination-append path) (string-append destination-directory "/" path)) + (define (bash-alias->pair line) + (if (string-prefix? "alias" (pk line)) + (let ((matched (string-match "alias (.+)=\"?'?([^\"']+)\"?'?" line))) + `(,(match:substring matched 1) . ,(match:substring matched 2))) + '())) + + (define (parse-aliases input) + (let loop ((line (read-line input)) + (result '())) + (if (eof-object? line) + (reverse result) + (loop (read-line input) + (cons (bash-alias->pair line) result))))) + (let ((rc (destination-append ".bashrc")) (profile (destination-append ".bash_profile")) (logout (destination-append ".bash_logout"))) `((service home-bash-service-type (home-bash-configuration + ,@(if (file-exists? rc) + `((aliases + ',(let* ((port (open-pipe* OPEN_READ "bash" "-i" "-c" "alias")) + (alist (parse-aliases port))) + (close-port port) + (filter (negate null?) alist)))) + '()) ,@(if (file-exists? rc) `((bashrc (list (local-file ,rc From patchwork Mon Nov 1 09:45:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Xinglu Chen X-Patchwork-Id: 34197 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 7FFFC27BBE3; Mon, 1 Nov 2021 09:47:11 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,T_DKIM_INVALID, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 3769D27BBE1 for ; Mon, 1 Nov 2021 09:47:11 +0000 (GMT) Received: from localhost ([::1]:57764 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mhTuI-0001MX-Ab for patchwork@mira.cbaines.net; Mon, 01 Nov 2021 05:47:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53026) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mhTuC-0001MO-1Y for guix-patches@gnu.org; Mon, 01 Nov 2021 05:47:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:50419) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mhTuA-0005Cy-9A for guix-patches@gnu.org; Mon, 01 Nov 2021 05:47:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mhTuA-0000Ec-7f for guix-patches@gnu.org; Mon, 01 Nov 2021 05:47:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#51543] [PATCH 2/2] doc: Document =?utf-8?b?4oCYaG9tZS1iYXNo?= =?utf-8?b?LWV4dGVuc2lvbuKAmQ==?= configuration record. Resent-From: Xinglu Chen Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 01 Nov 2021 09:47:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51543 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 51543@debbugs.gnu.org Received: via spool by 51543-submit@debbugs.gnu.org id=B51543.1635759962816 (code B ref 51543); Mon, 01 Nov 2021 09:47:02 +0000 Received: (at 51543) by debbugs.gnu.org; 1 Nov 2021 09:46:02 +0000 Received: from localhost ([127.0.0.1]:33732 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mhTtC-0000Cz-6i for submit@debbugs.gnu.org; Mon, 01 Nov 2021 05:46:02 -0400 Received: from h87-96-130-155.cust.a3fiber.se ([87.96.130.155]:58052 helo=mail.yoctocell.xyz) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mhTt9-0000CT-Ts for 51543@debbugs.gnu.org; Mon, 01 Nov 2021 05:46:00 -0400 From: Xinglu Chen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yoctocell.xyz; s=mail; t=1635759954; bh=+71Bg1Xx4QPpgh8bQQTqrzvtJy1zVPyYARoenLbfqr8=; h=From:To:Subject:In-Reply-To:References:Date; b=YghpnZ7DFovn62j7db9TWVdDxmEcLFTLCH/0NHikIKHF6roW4qey2cjJWZ+nYom2I mMeXFDs6i5jehxoH2KA5jVO7AOWUkD6g8l5VzPRGP1QZbcvlw8iv3KVMdN9gNgMHL8 aUS/n2q+s72nNJAM0ZOqaP/G/pcxcNOitovuoWmk= In-Reply-To: References: Message-Id: Date: Mon, 01 Nov 2021 10:45:53 +0100 MIME-Version: 1.0 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+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * doc/guix.texi (Shells Home Services): Document ‘home-bash-extension’ configuration record. * gnu/home/services/shells.scm (generate-home-bash-documentation): Extract docstrings from ‘home-bash-extension’. Fixes: --- doc/guix.texi | 24 ++++++++++++++++++++++++ gnu/home/services/shells.scm | 14 ++++++++++---- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index f7312a5b30..a3b440f5c9 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -36206,7 +36206,31 @@ process for example). @end table +@end deftp + +To extend the Bash service, one has to use a @code{home-bash-extension}, +which contains mostly the same fields as @code{home-bash-configuration}. + +@deftp {Data Type} home-bash-extension +Available @code{home-bash-extension} fields are: + +@table @asis +@item @code{environment-variables} (default: @code{()}) (type: alist) +Association list of environment variables to set. + +@item @code{aliases} (default: @code{()}) (type: alist) +Association list of aliases to set. +@item @code{bash-profile} (default: @code{()}) (type: text-config) +List of file-like objects. + +@item @code{bashrc} (default: @code{()}) (type: text-config) +List of file-like objects. + +@item @code{bash-logout} (default: @code{()}) (type: text-config) +List of file-like objects. + +@end table @end deftp @subsubheading Zsh Home Service diff --git a/gnu/home/services/shells.scm b/gnu/home/services/shells.scm index bd1595a041..9eeb7153e3 100644 --- a/gnu/home/services/shells.scm +++ b/gnu/home/services/shells.scm @@ -648,10 +648,16 @@ (define (generate-home-shell-profile-documentation) 'home-shell-profile-configuration)) (define (generate-home-bash-documentation) - (generate-documentation - `((home-bash-configuration - ,home-bash-configuration-fields)) - 'home-bash-configuration)) + (string-append + (generate-documentation + `((home-bash-configuration + ,home-bash-configuration-fields)) + 'home-bash-configuration) + "\n\n" + (generate-documentation + `((home-bash-extension + ,home-bash-extension-fields)) + 'home-bash-extension))) (define (generate-home-zsh-documentation) (generate-documentation