From 3c1158ac4e5ef825a9b9a229a233fabd7cef334e Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Tue, 26 Oct 2021 16:01:40 +0200 Subject: profiles: Build the man database only if 'man-db' is in the profile. This allows us to skip the expensive man-db profile hook in most cases. Suggested by Liliana Marie Prikler . * guix/profiles.scm (manual-database/optional): New procedure. (%default-profile-hooks): Use it instead of 'manual-database'. * doc/guix.texi (Documentation): Add footnote about 'man -k' database creation. --- doc/guix.texi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'doc/guix.texi') diff --git a/doc/guix.texi b/doc/guix.texi index ea1973f02c..b35fb35770 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -36611,7 +36611,9 @@ $ info -k TLS @end example @noindent -The command below searches for the same keyword in man pages: +The command below searches for the same keyword in man +pages@footnote{The database searched by @command{man -k} is only created +in profiles that contain the @code{man-db} package.}: @example $ man -k TLS -- cgit v1.2.3 From 4b96998292442ec03024481c911d88f86c7c36b5 Mon Sep 17 00:00:00 2001 From: Xinglu Chen Date: Sun, 7 Nov 2021 12:36:19 +0100 Subject: home: services: bash: Add ‘aliases’ field. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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. Signed-off-by: Ludovic Courtès --- doc/guix.texi | 14 ++++++++ gnu/home/services/shells.scm | 83 ++++++++++++++++++++++++++++++++------------ guix/scripts/home/import.scm | 24 +++++++++++++ 3 files changed, 98 insertions(+), 23 deletions(-) (limited to 'doc/guix.texi') diff --git a/doc/guix.texi b/doc/guix.texi index b35fb35770..6d6dfd5177 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -36173,6 +36173,20 @@ Add sane defaults like reading @file{/etc/bashrc}, coloring output for @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 @@ source ~/.profile ;;; 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 @@ for @code{ls} provided by guix to @file{.bashrc}.") (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 @@ alias grep='grep --color=auto'\n") (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 @@ if [ -f ~/.bashrc ]; then source ~/.bashrc; fi ,@(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 @@ if [ -f ~/.bashrc ]; then source ~/.bashrc; fi (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 @@ if [ -f ~/.bashrc ]; then source ~/.bashrc; fi "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 @@ #: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 @@ FILE-NAME with \"-\", and return the basename of it." (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 -- cgit v1.2.3 From 2f665d4309053d5a9fe25bc93ee78d55dbc30cb7 Mon Sep 17 00:00:00 2001 From: Xinglu Chen Date: Sun, 7 Nov 2021 12:36:29 +0100 Subject: doc: Improve documentation of the Bash home service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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: Signed-off-by: Ludovic Courtès --- doc/guix.texi | 50 +++++++++++++++++++++++++++++++++++++++----- gnu/home/services/shells.scm | 45 ++++++++++++++++++++++++++------------- 2 files changed, 76 insertions(+), 19 deletions(-) (limited to 'doc/guix.texi') diff --git a/doc/guix.texi b/doc/guix.texi index 6d6dfd5177..76290d593e 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -36159,6 +36159,7 @@ Extend home-shell-profile service only if you really know what you do. @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 @@ Available @code{home-bash-configuration} fields are: 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 @@ be read in some cases (if the shell terminates by exec'ing another 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 @@ source ~/.profile "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 @@ if [ -f ~/.bashrc ]; then source ~/.bashrc; fi (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 @@ Install and configure Fish, the friendly interactive shell."))) '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 -- cgit v1.2.3 From b999c80c2e71bd4b3f26a18a321b7e7e7b580103 Mon Sep 17 00:00:00 2001 From: Xinglu Chen Date: Mon, 1 Nov 2021 11:55:26 +0100 Subject: import: egg: Allow imports of a specific version. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * guix/import/egg.scm (eggs-repository): Change URL. (egg-metadata): Accept optional #:version keyword argument. (egg->guix-package): Accept ‘version’ argument. (egg-recursive-import): Add ‘version’ argument and honor it. * guix/scripts/import/egg.scm (guix-import-egg): Parse a specification instead of just a package name. * doc/guix.texi (Invoking guix import): Document it. Signed-off-by: Ludovic Courtès --- doc/guix.texi | 8 +++++++- guix/import/egg.scm | 37 ++++++++++++++++++++----------------- guix/scripts/import/egg.scm | 34 +++++++++++++++++++--------------- 3 files changed, 46 insertions(+), 33 deletions(-) (limited to 'doc/guix.texi') diff --git a/doc/guix.texi b/doc/guix.texi index 76290d593e..3355a535ad 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -12166,7 +12166,7 @@ coexist. @cindex egg Import metadata for @uref{https://wiki.call-cc.org/eggs, CHICKEN eggs}. The information is taken from @file{PACKAGE.egg} files found in the -@uref{git://code.call-cc.org/eggs-5-latest, eggs-5-latest} Git +@uref{git://code.call-cc.org/eggs-5-all, eggs-5-all} Git repository. However, it does not provide all the information that we need, there is no ``description'' field, and the licenses used are not always precise (BSD is often used instead of BSD-N). @@ -12175,6 +12175,12 @@ always precise (BSD is often used instead of BSD-N). guix import egg sourcehut @end example +You can also ask for a specific version: + +@example +guix import egg arrays@@1.0 +@end example + Additional options include: @table @code @item --recursive diff --git a/guix/import/egg.scm b/guix/import/egg.scm index 89e7a9160d..ff9f5a0247 100644 --- a/guix/import/egg.scm +++ b/guix/import/egg.scm @@ -51,10 +51,10 @@ ;;; ;;; The following happens under the hood: ;;; -;;; * is a Git repository that contains -;;; the latest version of all CHICKEN eggs. We look clone this repository -;;; and retrieve the latest version number, and the PACKAGE.egg file, which -;;; contains a list of lists containing metadata about the egg. +;;; * is a Git repository that contains +;;; all versions of all CHICKEN eggs. We look clone this repository and, by +;;; default, retrieve the latest version number, and the PACKAGE.egg file, +;;; which contains a list of lists containing metadata about the egg. ;;; ;;; * All the eggs are stored as tarballs at ;;; , so we grab the tarball for @@ -96,7 +96,7 @@ NAME." (define (eggs-repository) "Update or fetch the latest version of the eggs repository and return the path to the repository." - (let* ((url "git://code.call-cc.org/eggs-5-latest") + (let* ((url "git://code.call-cc.org/eggs-5-all") (directory commit _ (update-cached-checkout url))) directory)) @@ -112,12 +112,13 @@ to the repository." (last directory) #f))) -(define* (egg-metadata name #:optional file) - "Return the package metadata file for the egg NAME, or if FILE is specified, -return the package metadata in FILE." +(define* (egg-metadata name #:key (version #f) (file #f)) + "Return the package metadata file for the egg NAME at version VERSION, or if +FILE is specified, return the package metadata in FILE." (call-with-input-file (or file (string-append (egg-directory name) "/" - (find-latest-version name) + (or version + (find-latest-version name)) "/" name ".egg")) read)) @@ -173,10 +174,11 @@ return the package metadata in FILE." ;;; Egg importer. ;;; -(define* (egg->guix-package name #:key (file #f) (source #f)) - "Import a CHICKEN egg called NAME from either the given .egg FILE, or from -the latest NAME metadata downloaded from the official repository if FILE is #f. -Return a record or #f on failure. +(define* (egg->guix-package name version #:key (file #f) (source #f)) + "Import a CHICKEN egg called NAME from either the given .egg FILE, or from the +latest NAME metadata downloaded from the official repository if FILE is #f. +Return a record or #f on failure. If VERSION is specified, import +the particular version from the egg repository. SOURCE is a ``file-like'' object containing the source code corresponding to the egg. If SOURCE is not specified, the latest tarball for egg NAME will be @@ -186,8 +188,8 @@ Specifying the SOURCE argument is mainly useful for developing a CHICKEN egg locally. Note that if FILE and SOURCE are specified, recursive import will not work." (define egg-content (if file - (egg-metadata name file) - (egg-metadata name))) + (egg-metadata name #:file file) + (egg-metadata name #:version version))) (if (not egg-content) (values #f '()) ; egg doesn't exist (let* ((version* (or (assoc-ref egg-content 'version) @@ -326,10 +328,11 @@ not work." (define egg->guix-package/m ;memoized variant (memoize egg->guix-package)) -(define (egg-recursive-import package-name) +(define* (egg-recursive-import package-name #:optional version) (recursive-import package-name + #:version version #:repo->guix-package (lambda* (name #:key version repo) - (egg->guix-package/m name)) + (egg->guix-package/m name version)) #:guix-name egg-name->guix-name)) diff --git a/guix/scripts/import/egg.scm b/guix/scripts/import/egg.scm index 829cdc2ca0..6a9657d12c 100644 --- a/guix/scripts/import/egg.scm +++ b/guix/scripts/import/egg.scm @@ -26,6 +26,7 @@ #:use-module (srfi srfi-1) #:use-module (srfi srfi-11) #:use-module (srfi srfi-37) + #:use-module (srfi srfi-71) #:use-module (ice-9 match) #:use-module (ice-9 format) #:export (guix-import-egg)) @@ -83,21 +84,24 @@ Import and convert the egg package for PACKAGE-NAME.\n")) (_ #f)) (reverse opts)))) (match args - ((package-name) - (if (assoc-ref opts 'recursive) - ;; Recursive import - (map (match-lambda - ((and ('package ('name name) . rest) pkg) - `(define-public ,(string->symbol name) - ,pkg)) - (_ #f)) - (egg-recursive-import package-name)) - ;; Single import - (let ((sexp (egg->guix-package package-name))) - (unless sexp - (leave (G_ "failed to download meta-data for package '~a'~%") - package-name)) - sexp))) + ((spec) + (let ((name version (package-name->name+version spec))) + (if (assoc-ref opts 'recursive) + ;; Recursive import + (map (match-lambda + ((and ('package ('name name) . rest) pkg) + `(define-public ,(string->symbol name) + ,pkg)) + (_ #f)) + (egg-recursive-import name version)) + ;; Single import + (let ((sexp (egg->guix-package name version))) + (unless sexp + (leave (G_ "failed to download meta-data for package '~a'~%") + (if version + (string-append name "@" version) + name))) + sexp)))) (() (leave (G_ "too few arguments~%"))) ((many ...) -- cgit v1.2.3