[PATCH 0/2] Some improvements to the Bash home service

  • Done
  • quality assurance status badge
Details
3 participants
  • Liliana Marie Prikler
  • Ludovic Courtès
  • Xinglu Chen
Owner
unassigned
Submitted by
Xinglu Chen
Severity
normal
X
X
Xinglu Chen wrote on 1 Nov 2021 10:43
(address . guix-patches@gnu.org)
cover.1635759704.git.public@yoctocell.xyz
This series adds an ‘aliases’ field to the Bash home service, and
documents the ‘home-bash-extension’ configuration record in the manual.

Xinglu Chen (2):
home: services: bash: Add ‘aliases’ field.
doc: Document ‘home-bash-extension’ configuration record.

doc/guix.texi | 38 ++++++++++++++
gnu/home/services/shells.scm | 99 ++++++++++++++++++++++++++----------
guix/scripts/home/import.scm | 24 +++++++++
3 files changed, 134 insertions(+), 27 deletions(-)


base-commit: 1a80b8909a521b91d30649a011b0257d0fadc18c
--
2.33.0
-----BEGIN PGP SIGNATURE-----

iQJJBAEBCAAzFiEEAVhh4yyK5+SEykIzrPUJmaL7XHkFAmF/trYVHHB1YmxpY0B5
b2N0b2NlbGwueHl6AAoJEKz1CZmi+1x5Jl8P/AldbcXXM5GLsfl5E382+hwiGr7L
b5+EAFkSgvr1qSdDIsVQqW7Zax0USHm9HGkwTXLFcZEo3+WQJdbN5yFoM+H7tnOD
uYuBOFTnoBK3iyHG59oNZH/pLjzO8/SATuGp+naXwsK75eV+ypVc5Mi7iqFAj1HK
VsRxiaDdjCwQTaQg4TfLEw9Cu2cfcq4SMnaEZlJYJeLZF5dvK1DxUNygmf2I4rPu
JsfwJSVa3KuRFD29jBl5YB4j9YOmZkyUZKm81VO4LZWBhJ8fds2xQKaN3851/H1I
EX6MDgDDPOl8g+096cwqKA1Vk5Xr2F/bdq9tQHYBRhsYXiw7rPw8R3f56fgm1heR
oFtXdeIUg53gHVeclctMl7ZCi4NJpRIPiRD+JzTfklPmd72r800z1lPhxVWyYYg8
Gb89exh6d65bt5WfYQ/g1ZZoOd66dfwJOqgieQDpIi3j/peBIX3d5KGJrJJXv96x
EmGOIoF67yrLEN4th5eq74IpZwv5kU+3tz27C+BXiXLMKblqrEJZWml2pWRuXVqB
px3qmX08tJPFKgEcwBivpDGDY466rc4wl593RLgz3NDYpm5LzwEyrTqwxX4gWCh6
nHjT1H8M8yNlcFqxHp3zB0g11s2jaQDANl6Qalcj873aWeknLSPdc52QrgQolhBf
HcG99TyZITWYmD4s
=/Tc6
-----END PGP SIGNATURE-----

X
X
Xinglu Chen wrote on 1 Nov 2021 10:45
[PATCH 1/2] home: services: bash: Add ‘ aliases’ field.
(address . 51543@debbugs.gnu.org)
231301123d2fe00e6c65e94ec45ffc906bf95ee1.1635759704.git.public@yoctocell.xyz
* 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(-)

Toggle diff (206 lines)
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
+ (($ <home-bash-configuration> _ _ _ 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
--
2.33.0
X
X
Xinglu Chen wrote on 1 Nov 2021 10:45
[PATCH 2/2] doc: Document ‘home-bash-extens ion’ configuration record.
(address . 51543@debbugs.gnu.org)
a92171a4ae30035432b14550243743c9b675e0a5.1635759705.git.public@yoctocell.xyz
* 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’.

---
doc/guix.texi | 24 ++++++++++++++++++++++++
gnu/home/services/shells.scm | 14 ++++++++++----
2 files changed, 34 insertions(+), 4 deletions(-)

Toggle diff (63 lines)
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
--
2.33.0
L
L
Liliana Marie Prikler wrote on 1 Nov 2021 11:45
Re: [PATCH 2/2] doc: Document ‘home-bash-extension’ configuration record.
8624d1b4164dd14846362d66005552705064de96.camel@gmail.com
Hi,

Am Montag, den 01.11.2021, 10:45 +0100 schrieb Xinglu Chen:
Toggle quote (27 lines)
> * 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: <https://issues.guix.gnu.org/50991>
> ---
> 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}.
This sounds like you're forcing people to extend their services. Write
it "You can extend the bash service by using home-bash-extension, whose
fields mostly mirror that of home-bash-service".

Toggle quote (22 lines)
> +@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
This documentation is a little sparse, don't you agree? Are the keys
to environment-variables strings or symbols? At which point are these
fields inserted into which files (e.g. do the aliases come before
profile or after it)?

If some field is already described as part of home-bash-service, you
might also want to link back to it, but you should still state where
the extension occurs. Is new code added to the front or to the back
for instance. (On that note, is the text-config type well-documented?)

Regards,
Liliana
X
X
Xinglu Chen wrote on 1 Nov 2021 14:22
Re: [bug#51543] [PATCH 2/2] doc: Document ‘home -bash-extension’ configuration record.
87k0hs57uu.fsf@disroot.org
Hi,

On Mon, Nov 01 2021, Liliana Marie Prikler wrote:

Toggle quote (34 lines)
> Hi,
>
> Am Montag, den 01.11.2021, 10:45 +0100 schrieb Xinglu Chen:
>> * 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: <https://issues.guix.gnu.org/50991>
>> ---
>> 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}.
> This sounds like you're forcing people to extend their services. Write
> it "You can extend the bash service by using home-bash-extension, whose
> fields mostly mirror that of home-bash-service".

Indeed, that sounds better.

Toggle quote (25 lines)
>> +@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
> This documentation is a little sparse, don't you agree? Are the keys
> to environment-variables strings or symbols?

The keys should be strings; the rules for
‘home-environment-variable-service-type’ apply here (see “11.3.1
Essential Home Services”).

Toggle quote (3 lines)
> At which point are these fields inserted into which files (e.g. do the
> aliases come before profile or after it)?

Good question! The contents of ‘aliases’ and ‘bashrc’ are put into
~/.bashrc, in that order. The contents of ‘bash-profile’ and
‘environment-variables’ are put into ~/.bash_profile, in that order.
This doesn’t seem that consistent, is there any preference to what order
should be used?

Toggle quote (6 lines)
> If some field is already described as part of home-bash-service, you
> might also want to link back to it, but you should still state where
> the extension occurs. Is new code added to the front or to the back
> for instance. (On that note, is the text-config type
> well-documented?)

I don’t think there is a way to link to ‘home-bash-configuration’ using
Texinfo; one can only link to “Shells Home Services”.
-----BEGIN PGP SIGNATURE-----

iQJJBAEBCAAzFiEEAVhh4yyK5+SEykIzrPUJmaL7XHkFAmF/6fkVHHB1YmxpY0B5
b2N0b2NlbGwueHl6AAoJEKz1CZmi+1x5MZ0P/0FcR1Mhify/gFakPR7+0yyZpIAr
hYWr1JyM/qfMXIN7MJjtGM8Fxi7FRYXT/mBjoxvl1shtHeJv1dU3i44g9nl+T+1f
ydnbUS3SMcWYYIGI2ZDkNVoE1yfL9ogvm9sX1k5EFyWwNysBkgCyVDuWfHLWhF8v
fj2C82r91mdFb5VEw/l1Yj1AhJ3PYEAuJ6Tb6s23UfkLb2oZsbug9+suJR92R72s
G3P5hdoM+YdvJk4L84nKOakXRq//uNTy8WOzZ+q/WUm+Zu1+TRHHkkFRz1D1uUnY
d+KxzzucsLEcmBMtW3HRddzlsrrt5J6l/Dx9Cfrh9kY4z947ClWObSb4S1T3Eon0
lAnsQOoO4JFygjcyuiGosITo/0HZJuEuGuHSO/gdZiFqrnpdb3CMl6kdbo32tXEj
lfFgdvVEgaQ+jHB86rsE3crbuvT0v6cP4+ltbx8FtTp3BgBoLvvIn+P8mQFLxYJ9
Kb8t02hXfwE7wJw7UM9cAse2RtmjlWPefROYONaAU/Koy8ABJsm29GIzDpPNe2JM
RlhBMzXPZypA+wjOg1kDqsnboTDPEqYLspdro8hFxBdUD7cOqXajPrgrrh0G0L0y
Y+ZN6A4w0lkdTPLJ1nJeMjVp1fc60v/ryaUuClOix35gpJ+aO+YKJP4HI2f6CifM
U/p74e+AKf+Kj88Q
=fJwV
-----END PGP SIGNATURE-----

L
L
Liliana Marie Prikler wrote on 1 Nov 2021 17:38
Re: [bug#51543] [PATCH 2/2] doc: Document ‘home-bash-extension’ configuration record.
ceec77e319e8f3d6ecd6c5b7683a6f511e07a183.camel@gmail.com
Hi,

Am Montag, den 01.11.2021, 14:22 +0100 schrieb Xinglu Chen:
Toggle quote (5 lines)
> [...]
>
> The keys should be strings; the rules for
> ‘home-environment-variable-service-type’ apply here (see “11.3.1
> Essential Home Services”).
You might want to explicitly state that.

Toggle quote (8 lines)
> > At which point are these fields inserted into which files (e.g. do
> > the aliases come before profile or after it)?
>
> Good question! The contents of ‘aliases’ and ‘bashrc’ are put into
> ~/.bashrc, in that order. The contents of ‘bash-profile’ and
> ‘environment-variables’ are put into ~/.bash_profile, in that order.
> This doesn’t seem that consistent, is there any preference to what
> order should be used?
You can use whichever makes sense to you, I'm just pointing out that it
ought to be documented.

Toggle quote (8 lines)
> > If some field is already described as part of home-bash-service,
> > you might also want to link back to it, but you should still state
> > where the extension occurs. Is new code added to the front or to
> > the back for instance. (On that note, is the text-config type
> > well-documented?)
>
> I don’t think there is a way to link to ‘home-bash-configuration’
> using Texinfo; one can only link to “Shells Home Services”.
Texinfo should support anchors, which can point to arbitrary text. Of
course one could overdo it by linking each and every field, but imho
having one link for context is better than none.

Thoughts?
X
X
Xinglu Chen wrote on 5 Nov 2021 12:56
Re: [bug#51543] [PATCH 2/2] doc: Document ‘home -bash-extension’ configuration record.
87tugq4xys.fsf@disroot.org
Hi,

On Mon, Nov 01 2021, Liliana Marie Prikler wrote:

Toggle quote (10 lines)
> Hi,
>
> Am Montag, den 01.11.2021, 14:22 +0100 schrieb Xinglu Chen:
>> [...]
>>
>> The keys should be strings; the rules for
>> ‘home-environment-variable-service-type’ apply here (see “11.3.1
>> Essential Home Services”).
> You might want to explicitly state that.

Yes, good idea.

Toggle quote (23 lines)
>> > At which point are these fields inserted into which files (e.g. do
>> > the aliases come before profile or after it)?
>>
>> Good question! The contents of ‘aliases’ and ‘bashrc’ are put into
>> ~/.bashrc, in that order. The contents of ‘bash-profile’ and
>> ‘environment-variables’ are put into ~/.bash_profile, in that order.
>> This doesn’t seem that consistent, is there any preference to what
>> order should be used?
> You can use whichever makes sense to you, I'm just pointing out that it
> ought to be documented.
>
>> > If some field is already described as part of home-bash-service,
>> > you might also want to link back to it, but you should still state
>> > where the extension occurs. Is new code added to the front or to
>> > the back for instance. (On that note, is the text-config type
>> > well-documented?)
>>
>> I don’t think there is a way to link to ‘home-bash-configuration’
>> using Texinfo; one can only link to “Shells Home Services”.
> Texinfo should support anchors, which can point to arbitrary text. Of
> course one could overdo it by linking each and every field, but imho
> having one link for context is better than none.

Ah, that would do it. Thanks for the pointer.

I will send an updated series.
-----BEGIN PGP SIGNATURE-----

iQJJBAEBCAAzFiEEAVhh4yyK5+SEykIzrPUJmaL7XHkFAmGFHAsVHHB1YmxpY0B5
b2N0b2NlbGwueHl6AAoJEKz1CZmi+1x5oFkP/2tuB4bNBzEMZXWTXHX3LRJNWPPD
zCbKWDW7EAwhKe/1d6wTkPQaiaz1A0NphncDJCqhHB/PJ0ixgLC7U9SdnB6Y+3bA
/0zMUcIJITuN9EzBEKJHQqdJ7oPCE3o+C9W3RF0kDyaPfNJAxMr5+DaW4Vzxeua5
4h2Hx/qYw4QWdHVpTE3f11d+da5qJ7PlhDkzLoEq6Tln+1bFvtq8EGLldvK+Od7d
r72pjf5GWgbOJaR3OWizpuA7gOTeMIt6rTjl9+BXDDLChl3ICfOSKrbS4QIGU738
Gx/bYGfsAodTXcoBlYStkxm5hy3kV9vY9Qwldcm2fItaK4mphCqYr0TT8mOz20Qk
q+++8n/bDxzJtBOhdz1fMj8Oi7t21WomxLbOshIDuTXnc4ygaKOwR5jpod6aaSGV
MAVbtNyVW7z5judCzDFncfFLMC4oTiyuB+R4LOMW5Xb7IUrP37+wwWlymmLaQfds
ieKFga2iQK4KD8XE7RQVMEsTZZ+ICVEoogtpiY917M+/Y4gg3IPlOohGMivtrcJ+
78PcEFUdqXi+5/AklayIJF37jNhJWdq+Dc4+qeqxRK6s+a581T4adpkZreihKmHf
zRlqOJho8H/a2wOizfgherOtPAcfv2k8CA3nJBt7UMiZ3c1EX4ZSKxJZF6g5wsFs
RyZqUQpbI+B9BVDl
=nS8M
-----END PGP SIGNATURE-----

X
X
Xinglu Chen wrote on 5 Nov 2021 15:03
[PATCH 0/2] Some improvements to the Bash home service
(address . 51543@debbugs.gnu.org)(name . Liliana Marie Prikler)(address . liliana.prikler@gmail.com)
cover.1636120778.git.public@yoctocell.xyz
Changes since v1:

* Improvements to the documentation of ‘home-bash-configuration’ and
‘home-bash-extension’.

* Reorder the serialization of the ‘guix-defaults?’, ‘alias’, and
‘bashrc’ fields.

Xinglu Chen (2):
home: services: bash: Add ‘aliases’ field.
doc: Improve documentation of the Bash home service

doc/guix.texi | 54 +++++++++++++++++-
gnu/home/services/shells.scm | 108 +++++++++++++++++++++++++----------
guix/scripts/home/import.scm | 24 ++++++++
3 files changed, 153 insertions(+), 33 deletions(-)


base-commit: 0e19713c1fbfd3a01347e0d490434a53a596ed3c
--
2.33.0
-----BEGIN PGP SIGNATURE-----

iQJJBAEBCAAzFiEEAVhh4yyK5+SEykIzrPUJmaL7XHkFAmGFOZcVHHB1YmxpY0B5
b2N0b2NlbGwueHl6AAoJEKz1CZmi+1x5EL8P/jcrT+hp+GgipY7ybOBsEX19v2gM
TEbuAEXaUP0fnBvE4EcAVYpwb5X6mN1ZMo0F3Cks+I9aMzloXJyxFr+vB6dsSiac
QyLotm//rf/7UXv4etPwNUQiz3S6x8ovYc++TbnRKfPeIifHI8p/O2nPTEo74Znn
j6q4Wue9B6Dclog2SZLOrMGEO+N/xXPEZISlzX+ad24yWFSU3Gft1eECmfFTB1VE
qZke1SnZHbRwjSfT+9HwC62mC+wIBv3geuj145Ta/shcHmSXJUh6kcY71m38e9rv
q3rA7YpwUvDhDQkixQ1zLB4aZpMlWBTEU7C2lrh49bKrzjUTagJzSTic+sKVZFil
s0qHeI6JFgJEp13v5lv+JGJ5vCH1cy5YvEOQFUrRJ6eMl3QOdOkPippZJXbP7vG5
yP/KTlCS3FtG1nAxMr5UK+UFimTeyKMlvyXikv9uWbqQxvT8ZS8Kn8MpPd7KXkcr
HbyyhkIaglaJeY45R775ewVET87Th1X7p01P6oVgdaFIrqci4rTj8Vp6sQUT585h
Sr1UCjGjrhmVHBlouWWDZjxJP0g42q3NM6imqRsWD3ps+QuHNieI/La+9NOfEhVp
cRvFqelO6o4xjMiFw8le+N3TzATTlhQgpjcii58iZV68We0T71RkPrjX0BuPgg4F
yZXwpcrpdnpY4LNo
=Az7c
-----END PGP SIGNATURE-----

X
X
Xinglu Chen wrote on 5 Nov 2021 15:03
[PATCH 1/2] home: services: bash: Add ‘ aliases’ field.
(address . 51543@debbugs.gnu.org)(name . Liliana Marie Prikler)(address . liliana.prikler@gmail.com)
f8c3f9384fea4f5aa1bed43e203ed073ab3b4c21.1636120778.git.public@yoctocell.xyz
* 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(-)

Toggle diff (204 lines)
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
+ (($ <home-bash-configuration> _ _ _ 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
--
2.33.0
X
X
Xinglu Chen wrote on 5 Nov 2021 15:03
[PATCH 2/2] doc: Improve documentation of the Bash home service
(address . 51543@debbugs.gnu.org)(name . Liliana Marie Prikler)(address . liliana.prikler@gmail.com)
c72b1663698eb662885e229a711a9e17a4a281a1.1636120778.git.public@yoctocell.xyz
* 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.

---
doc/guix.texi | 44 ++++++++++++++++++++++++++++++++----
gnu/home/services/shells.scm | 29 ++++++++++++++++--------
2 files changed, 59 insertions(+), 14 deletions(-)

Toggle diff (128 lines)
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
--
2.33.0
L
L
Liliana Marie Prikler wrote on 5 Nov 2021 20:36
572780a1911e6972d9d956fd648a53c0d773b75b.camel@gmail.com
Hi,

Am Freitag, den 05.11.2021, 15:03 +0100 schrieb Xinglu Chen:
Toggle quote (7 lines)
> @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.
Regarding this option, you might want to instead provide a sane-
defaults-bash-service or something along those lines instead of using
an extra field. However, as this field already existed before, this is
not a blocker for this series.



Toggle quote (36 lines)
> [...]
> @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
Is there a reason why this documentation stayed more or less the same?
I see the fields have an updated documentation, but it appears not to
be reflected here. Or are strings taken from the [1/2] patch?

Either way, since the data types ought to be already known, you should
write something along the lines of "Additional environment variables to
set. These will be concatenated with the environment variables from
other extensions and the base service to form one coherent block of
environment variables." and so on, focusing on what it does rather than
what it is.

Cheers
X
X
Xinglu Chen wrote on 7 Nov 2021 12:20
87tugo2owc.fsf@disroot.org
Hi,

On Fri, Nov 05 2021, Liliana Marie Prikler wrote:

Toggle quote (15 lines)
> Hi,
>
> Am Freitag, den 05.11.2021, 15:03 +0100 schrieb Xinglu Chen:
>> @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.
> Regarding this option, you might want to instead provide a sane-
> defaults-bash-service or something along those lines instead of using
> an extra field. However, as this field already existed before, this is
> not a blocker for this series.

That sounds like a good idea!

Toggle quote (40 lines)
>> [...]
>> @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
> Is there a reason why this documentation stayed more or less the same?
> I see the fields have an updated documentation, but it appears not to
> be reflected here. Or are strings taken from the [1/2] patch?

I didn’t change the docstrings for ‘home-bash-extension’, only for
‘home-bash-configuration’.

Toggle quote (7 lines)
> Either way, since the data types ought to be already known, you should
> write something along the lines of "Additional environment variables to
> set. These will be concatenated with the environment variables from
> other extensions and the base service to form one coherent block of
> environment variables." and so on, focusing on what it does rather than
> what it is.

Yeah, that sounds a lot more informative than the current docstring.
-----BEGIN PGP SIGNATURE-----

iQJJBAEBCAAzFiEEAVhh4yyK5+SEykIzrPUJmaL7XHkFAmGHtnMVHHB1YmxpY0B5
b2N0b2NlbGwueHl6AAoJEKz1CZmi+1x5U7gP/0DVO3jNB58l9gqzhMdKWhubw6ub
ojFVEKOfNMoE9+mPTaNopfUqS+a0Inau0EpfCGaG5EnsyHTZn6XFKW6foP4O5S2N
z+w3uTwNvGwxP/aHDhIIjez3BtKMihrpuB/lgPdHbb9CfX4NC1Xlh8YZkOhYuswZ
lB/4bLXdHT6az8fXn+WSmECdIAj3q9H6NXqbcelgXWSNvAWnl7L4i2w+iv2v6iUv
YXtLoDEFUT1Xz7cvwHsyvnYDVned4/v16OHdO4hp2DMJOE2sh8gqw4Tm1KL/mwAm
yCoWF4ilCIa8vIkhv0EZKuQdCMhDJSLtFNcVOIcfkZMBEdb9aLEGt+7X/gNBn3j4
ncfg4m7kSkLRhenbeicpYs/AJqc93vip1NIH5Pb6ODZFoxcyTycUWF2mg3qB0g58
3rkjc3wq2wTdqk5Ng0SIdSEQ5XLf7NLK6QeB4uFFE/5X8Dkt31DqUZYCsaldBK7g
fSgK469G9iLtoTPJJ3tMoEDROQ/edshJicJUGcNQXYBtAkVZ/Sg3bITAnNWQTU+A
N+yYLzM8vzmym9Zn67XtKvhj/Iam0wWkd//zDfl76UTCWww3JNENAg6tQoWdJDE1
1DDtywo6OpYXz4V+WJO4AOJBCB4d4Th0znQPKeLB8oy9wgCiYmwFutUba0rEFEVU
MzlxUGEg5eYnv2UZ
=2XaU
-----END PGP SIGNATURE-----

X
X
Xinglu Chen wrote on 7 Nov 2021 12:36
[PATCH v3 0/2] Some improvements to the Bash home service
(address . 51543@debbugs.gnu.org)(name . Liliana Marie Prikler)(address . liliana.prikler@gmail.com)
cover.1636284793.git.public@yoctocell.xyz
Changes since v2:

* Improve docstrings of ‘home-bash-extension’ fields by describing what
they do instead of what they ought to be.

Xinglu Chen (2):
home: services: bash: Add ‘aliases’ field.
doc: Improve documentation of the Bash home service

doc/guix.texi | 60 ++++++++++++++++-
gnu/home/services/shells.scm | 122 +++++++++++++++++++++++++----------
guix/scripts/home/import.scm | 24 +++++++
3 files changed, 169 insertions(+), 37 deletions(-)


base-commit: 1ffc0a6be3c1613b2d99ceea098174d1f11f6f3f
--
2.33.0
-----BEGIN PGP SIGNATURE-----

iQJJBAEBCAAzFiEEAVhh4yyK5+SEykIzrPUJmaL7XHkFAmGHuiwVHHB1YmxpY0B5
b2N0b2NlbGwueHl6AAoJEKz1CZmi+1x5FuIP/RbGS7VAAFYx2JAnj8XsR6D6W7Eq
cyMXdZDXy/vTAsuuaCU3xQqtn+WdBsmu1h+oK7yRnNql+bRPJvZMOYvE3k5i4Kd6
qeho8SdHV8Soqmb2TXL+OGxDUOLjqEBSNxknH90bU3bvvOdg01UpbVTAIihKGdjH
RWBhUlTewxRRn/ioTXfSNdxtYUnJR1x/LMIr8/NhsEoRP71DzUeXWZdiE+QY2dIm
39Yod7LfsWLp+zMlOqixk7kBYlYjo5TlXzlVJU0bFwXWiXsyCGb+I7m1w3GFhLNa
X4xA9bwYzUZ175bUDw5GY+I1XdE0fk2J0x+WHHfsiPcG81OHWBSJ0owY5Vcp1SKk
x6kGd4UxxSkuJ71YijPOsugzYU2mbJgc3hJLSuT05jakka5NB5V0Po7q3BdK1iVE
gLYevPVlq037U+54OJcyFJ3zlkzCGMWKYixZta7xA+PqU8YbtfyunlamqGGJoarT
Lp9qfteE9CrbJrNBzm1E7JquPGPBzSBAonQOYZTljTMkW97xVg4BLHOyAtcbvY+3
7sD8iGx1UXVmQCIsXK+VMpDUQvrUBKiJDsxp9J7IdoTbTxesJ58fN4/Gnr05ofls
mTI0/+1ViiiWQaJ24YsQUoQia1yI1CLcuwlJ6jR71dnK43Oeg0cge5PX8Cxcgnmd
o+u7u+wzP+V/9TYZ
=mLbt
-----END PGP SIGNATURE-----

X
X
Xinglu Chen wrote on 7 Nov 2021 12:36
[PATCH v3 1/2] home: services: bash: Add ‘aliases’ field.
(address . 51543@debbugs.gnu.org)(name . Liliana Marie Prikler)(address . liliana.prikler@gmail.com)
3a13e86e446d35aa456da06750ad658ba49fd48b.1636284793.git.public@yoctocell.xyz
* 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(-)

Toggle diff (204 lines)
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
+ (($ <home-bash-configuration> _ _ _ 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
--
2.33.0
X
X
Xinglu Chen wrote on 7 Nov 2021 12:36
[PATCH v3 2/2] doc: Improve documentation of the Bash home service
(address . 51543@debbugs.gnu.org)(name . Liliana Marie Prikler)(address . liliana.prikler@gmail.com)
8945ebff245fc62c8ba59133e3116b6f68d0aa9c.1636284793.git.public@yoctocell.xyz
* 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.
(home-bash-extension): Likewise.

---
doc/guix.texi | 50 ++++++++++++++++++++++++++++++++----
gnu/home/services/shells.scm | 45 ++++++++++++++++++++++----------
2 files changed, 76 insertions(+), 19 deletions(-)

Toggle diff (165 lines)
diff --git a/doc/guix.texi b/doc/guix.texi
index f7312a5b30..db1bf6efa7 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,41 @@
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)
+Additional environment variables to set. These will be combined with the
+environment variables from other extensions and the base service to form one
+coherent block of environment variables.
+
+@item @code{aliases} (default: @code{()}) (type: alist)
+Additional aliases to set. These will be combined with the aliases from
+other extensions and the base service.
+@item @code{bash-profile} (default: @code{()}) (type: text-config)
+Additional text blocks to add to @file{.bash_profile}, which will be combined
+with text blocks from other extensions and the base service.
+
+@item @code{bashrc} (default: @code{()}) (type: text-config)
+Additional text blocks to add to @file{.bashrc}, which will be combined
+with text blocks from other extensions and the base service.
+
+@item @code{bash-logout} (default: @code{()}) (type: text-config)
+Additional text blocks to add to @file{.bash_logout}, which will be combined
+with text blocks from other extensions and the base service.
+
+@end table
@end deftp
@subsubheading Zsh Home Service
diff --git a/gnu/home/services/shells.scm b/gnu/home/services/shells.scm
index f24e47f762..81d07da86c 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\"))
@@ -450,19 +455,25 @@ (define (add-bash-packages config)
(define-configuration/no-serialization home-bash-extension
(environment-variables
(alist '())
- "Association list of environment variables to set.")
+ "Additional environment variables to set. These will be combined with the
+environment variables from other extensions and the base service to form one
+coherent block of environment variables.")
(aliases
(alist '())
- "Association list of aliases to set.")
+ "Additional aliases to set. These will be combined with the aliases from
+other extensions and the base service.")
(bash-profile
(text-config '())
- "List of file-like objects.")
+ "Additional text blocks to add to @file{.bash_profile}, which will be combined
+with text blocks from other extensions and the base service.")
(bashrc
(text-config '())
- "List of file-like objects.")
+ "Additional text blocks to add to @file{.bashrc}, which will be combined
+with text blocks from other extensions and the base service.")
(bash-logout
(text-config '())
- "List of file-like objects."))
+ "Additional text blocks to add to @file{.bash_logout}, which will be combined
+with text blocks from other extensions and the base service."))
(define (home-bash-extensions original-config extension-configs)
(match original-config
@@ -646,10 +657,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
--
2.33.0
L
L
Liliana Marie Prikler wrote on 7 Nov 2021 21:18
6a6c007ff1a9746b47ee0ba00e16db38fd38d244.camel@gmail.com
Am Sonntag, den 07.11.2021, 12:36 +0100 schrieb Xinglu Chen:
Toggle quote (10 lines)
> * 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.
> (home-bash-extension): Likewise.
>
> Fixes: <https://issues.guix.gnu.org/50991>
The docstrings LGTM now. This series is probably safe to go to master,
though you might want to wait for people to complain about the addition
of a field possibly breaking ABI and what not :P

Cheers
L
L
Ludovic Courtès wrote on 7 Nov 2021 21:58
Re: bug#51543: [PATCH 0/2] Some improvements to the Bash home service
(name . Xinglu Chen)(address . public@yoctocell.xyz)
87zgqfk7jb.fsf_-_@gnu.org
Hello,

Xinglu Chen <public@yoctocell.xyz> skribis:

Toggle quote (3 lines)
> home: services: bash: Add ‘aliases’ field.
> doc: Improve documentation of the Bash home service

Applied, thanks!

Liliana Marie Prikler <liliana.prikler@gmail.com> skribis:

Toggle quote (4 lines)
> The docstrings LGTM now. This series is probably safe to go to master,
> though you might want to wait for people to complain about the addition
> of a field possibly breaking ABI and what not :P

Users won’t see any ABI breakage so I think we’re fine. Applied!

Thanks Xinglu & Liliana!

Ludo’.
Closed
L
L
Ludovic Courtès wrote on 13 Nov 2021 21:35
(name . Xinglu Chen)(address . public@yoctocell.xyz)
87r1bjbxp3.fsf_-_@gnu.org
Hi!

Xinglu Chen <public@yoctocell.xyz> skribis:

Toggle quote (3 lines)
> home: services: bash: Add ‘aliases’ field.
> doc: Improve documentation of the Bash home service

I had overlooked it but it breaks tests/guix-home.sh and
tests/home-import.scm. Could you take a look and send a patch in a new
issue?

Thanks,
Ludo’.
?