From patchwork Fri Nov 5 14:03:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Xinglu Chen X-Patchwork-Id: 34258 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 DEDB127BBE3; Fri, 5 Nov 2021 14:07:17 +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 792A827BBE1 for ; Fri, 5 Nov 2021 14:07:17 +0000 (GMT) Received: from localhost ([::1]:44726 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mizsC-0003vG-Hb for patchwork@mira.cbaines.net; Fri, 05 Nov 2021 10:07:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35668) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mizp4-0006LK-FP for guix-patches@gnu.org; Fri, 05 Nov 2021 10:04:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:35171) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mizp4-0006b8-6q for guix-patches@gnu.org; Fri, 05 Nov 2021 10:04:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mizp4-0007Ng-3A for guix-patches@gnu.org; Fri, 05 Nov 2021 10:04:02 -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: Fri, 05 Nov 2021 14:04: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 Cc: Liliana Marie Prikler Received: via spool by 51543-submit@debbugs.gnu.org id=B51543.163612100728309 (code B ref 51543); Fri, 05 Nov 2021 14:04:02 +0000 Received: (at 51543) by debbugs.gnu.org; 5 Nov 2021 14:03:27 +0000 Received: from localhost ([127.0.0.1]:46713 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mizoU-0007MW-Nh for submit@debbugs.gnu.org; Fri, 05 Nov 2021 10:03:27 -0400 Received: from h87-96-130-155.cust.a3fiber.se ([87.96.130.155]:33854 helo=mail.yoctocell.xyz) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mizoL-0007Lz-46 for 51543@debbugs.gnu.org; Fri, 05 Nov 2021 10:03:25 -0400 From: Xinglu Chen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yoctocell.xyz; s=mail; t=1636120991; bh=iBLwIFgOsXIxcoZJgOGwguU56vQ4c0+RqPlbomA23A4=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=iriNTP4d1MjMazcg+RPCGe2AJsJhuVUnxS6OsZyxZi9x+4tzDFGPuxbKstNXUPqB3 7dH9w4bx24Y9RdOw8wdUmBxptpqt1Att0NQb2gqHLAc+63NLHU6BjkcfdrxOOGRjX9 bKNbPHbTWyYMlDMjuY6+rSo7hpJU5+BIeVFHv9P8= In-Reply-To: References: Message-Id: Date: Fri, 05 Nov 2021 15:03:11 +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 | 83 ++++++++++++++++++++++++++---------- guix/scripts/home/import.scm | 24 +++++++++++ 3 files changed, 98 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..f24e47f762 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,10 @@ (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))) + (cons (serialize-field field) + (if extra-content extra-content '())))) '()))) (filter @@ -413,8 +440,8 @@ (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 (serialize-field 'aliases) guix-bashrc) + (list (serialize-field 'alises)))) (file-if-not-empty 'bash-logout))))) (define (add-bash-packages config) @@ -424,6 +451,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 +465,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..fbf89069a7 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" 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 Fri Nov 5 14:03:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Xinglu Chen X-Patchwork-Id: 34259 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 7C72027BBE3; Fri, 5 Nov 2021 14:07:47 +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 F3FE927BBE1 for ; Fri, 5 Nov 2021 14:07:46 +0000 (GMT) Received: from localhost ([::1]:45994 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mizsg-0004pk-4y for patchwork@mira.cbaines.net; Fri, 05 Nov 2021 10:07:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35670) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mizp4-0006NP-RO for guix-patches@gnu.org; Fri, 05 Nov 2021 10:04:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:35172) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mizp4-0006bD-JR for guix-patches@gnu.org; Fri, 05 Nov 2021 10:04:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mizp4-0007Nn-Fw for guix-patches@gnu.org; Fri, 05 Nov 2021 10:04:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#51543] [PATCH 2/2] doc: Improve documentation of the Bash home service Resent-From: Xinglu Chen Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 05 Nov 2021 14:04: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 Cc: Liliana Marie Prikler Received: via spool by 51543-submit@debbugs.gnu.org id=B51543.163612101928336 (code B ref 51543); Fri, 05 Nov 2021 14:04:02 +0000 Received: (at 51543) by debbugs.gnu.org; 5 Nov 2021 14:03:39 +0000 Received: from localhost ([127.0.0.1]:46716 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mizoh-0007Mx-Bj for submit@debbugs.gnu.org; Fri, 05 Nov 2021 10:03:39 -0400 Received: from h87-96-130-155.cust.a3fiber.se ([87.96.130.155]:33924 helo=mail.yoctocell.xyz) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mizog-0007Mj-BY for 51543@debbugs.gnu.org; Fri, 05 Nov 2021 10:03:38 -0400 From: Xinglu Chen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yoctocell.xyz; s=mail; t=1636121012; bh=gkfAFg7N1avHfumXzUmptlBSP1zEaobAGMkOLMgwhIU=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=K1ppp8gKD8klGE6sEAvV81aNM1k9uLmxlEVpDDWfw6AE8qIBj1T2CVueK6Pxyb2zj o4Cigyzj1vmlwYtauFCyoVIO5wkvsqq3XFyvI5FRhera0Dw6AbyKJYP1ER1O4AQifN Pvkk+WWfCuw09nOAGa0SjAh23BxU1GUNU3UYrWas= In-Reply-To: References: Message-Id: Date: Fri, 05 Nov 2021 15:03:18 +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’. (home-bash-configuration): Expound on docstrings. Fixes: --- doc/guix.texi | 44 ++++++++++++++++++++++++++++++++---- gnu/home/services/shells.scm | 29 ++++++++++++++++-------- 2 files changed, 59 insertions(+), 14 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index f7312a5b30..002193e994 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -36159,6 +36159,7 @@ @subsubheading Bash Home Service +@anchor{home-bash-configuration} @deftp {Data Type} home-bash-configuration Available @code{home-bash-configuration} fields are: @@ -36167,15 +36168,20 @@ The Bash package to use. @item @code{guix-defaults?} (default: @code{#t}) (type: boolean) -Add sane defaults like reading @file{/etc/bashrc}, coloring output for -@code{ls} provided by guix to @file{.bashrc}. +Add sane defaults like reading @file{/etc/bashrc} and coloring the output of +@command{ls} to the end of the @file{.bashrc} file. @item @code{environment-variables} (default: @code{()}) (type: alist) -Association list of environment variables to set for the Bash session. +Association list of environment variables to set for the Bash session. The +rules for the @code{home-environment-variables-service-type} apply +here (@pxref{Essential Home Services}). The contents of this field will be +added after the contents of the @code{bash-profile} field. @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: +Association list of aliases to set for the Bash session. The aliases +will be defined after the contents of the @code{bashrc} field has been +put in the @file{.bashrc} file. The alias will automatically be quoted, +so something line this: @lisp '((\"ls\" . \"ls -alF\")) @@ -36206,7 +36212,35 @@ process for example). @end table +@end deftp + +You can extend the Bash service by using the @code{home-bash-extension} +configuration record, whose fields most mirror that of +@code{home-bash-configuration} (@pxref{home-bash-configuration}). The +contents of the extensions will be added to the end of the corresponding +Bash configuration files (@pxref{Bash Startup Files,,, bash, The GNU +Bash Reference Manual}. + +@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 f24e47f762..9b8427da7b 100644 --- a/gnu/home/services/shells.scm +++ b/gnu/home/services/shells.scm @@ -323,16 +323,21 @@ (define-configuration home-bash-configuration "The Bash package to use.") (guix-defaults? (boolean #t) - "Add sane defaults like reading @file{/etc/bashrc}, coloring output -for @code{ls} provided by guix to @file{.bashrc}.") + "Add sane defaults like reading @file{/etc/bashrc} and coloring the output of +@command{ls} to the end of the @file{.bashrc} file.") (environment-variables (alist '()) - "Association list of environment variables to set for the Bash session." + "Association list of environment variables to set for the Bash session. The +rules for the @code{home-environment-variables-service-type} apply +here (@pxref{Essential Home Services}). The contents of this field will be +added after the contents of the @code{bash-profile} field." 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: + "Association list of aliases to set for the Bash session. The aliases will be +defined after the contents of the @code{bashrc} field has been put in the +@file{.bashrc} file. The alias will automatically be quoted, so something line +this: @lisp '((\"ls\" . \"ls -alF\")) @@ -646,10 +651,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