~abcdw/rde-devel

gnu: home-services: shells: Add field for environment variables v1 APPLIED

Xinglu Chen: 1
 gnu: home-services: shells: Add field for environment variables

 1 files changed, 57 insertions(+), 38 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~abcdw/rde-devel/patches/23163/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH] gnu: home-services: shells: Add field for environment variables Export this patch

* shells.scm (serialize-alist): New procedure.
(home-bash-configuration): Add ‘environment-variable’ field.
(home-zsh-configuration): Likewise.
---
 gnu/home-services/shells.scm | 95 +++++++++++++++++++++---------------
 1 file changed, 57 insertions(+), 38 deletions(-)

diff --git a/gnu/home-services/shells.scm b/gnu/home-services/shells.scm
index 9c7c27a..d6e9b50 100644
--- a/gnu/home-services/shells.scm
+++ b/gnu/home-services/shells.scm
@@ -10,6 +10,7 @@
  #:use-module (guix packages)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-26)
  #:use-module (ice-9 match)

  #:export (home-shell-profile-service-type
	    home-shell-profile-configuration
@@ -83,17 +84,30 @@ for environment initialization of POSIX compliant login shells.  This
service type can be extended with a list of strings or gexps.")))

(define (serialize-boolean field-name val) "")
(define (serialize-alist field-name val)
  (append-map
   (match-lambda
     ((key . #f)
      "")
     ((key . #t)
      #~(string-append "export " #$key "\n"))
     ((key . value)
      #~(string-append "export " #$key "=" #$value "\n")))
   val))

(define-configuration home-zsh-configuration
  (package
   (package zsh)
   "The Zsh package to use.")
    (package zsh)
    "The Zsh package to use.")
  (xdg-flavor?
   (boolean #t)
   "Place all the configs to @file{$XDG_CONFIG_HOME/zsh}.  Makes
@file{~/.zshenv} to set @env{ZDOTDIR} to @file{$XDG_CONFIG_HOME/zsh}.
Shell startup process will continue with
@file{$XDG_CONFIG_HOME/zsh/.zshenv}.")
  (environment-variables
   (alist '())
   "Association list of environment variables to set for the Zsh session.")
  (zshenv
   (text-config '())
   "List of strings or gexps, which will be added to @file{.zshenv}.
@@ -166,7 +180,8 @@ another process for example)."))
          (if xdg-flavor?
              "export ZDOTDIR=${XDG_CONFIG_HOME:-$HOME/.config}/zsh\n"
              "")
          (serialize-field 'zshenv)))
          (serialize-field 'zshenv)
          (serialize-field 'environment-variables)))
       (,(prefix-file "zprofile")
        ,(mixed-text-file
          "zprofile"
@@ -252,6 +267,9 @@ source ~/.profile
   (boolean #t)
   "Add sane defaults like reading @file{/etc/bashrc}, coloring output
for @code{ls} provided by guix to @file{.bashrc}.")
  (environment-variables
   (alist '())
   "Association list of environment variables to set for the Bash session.")
  (bash-profile
   (text-config '())
   "List of strings or gexps, which will be added to @file{.bash_profile}.
@@ -307,33 +325,33 @@ alias ll='ls -l'
alias grep='grep --color=auto'\n")

(define (add-bash-configuration config)
    (define (filter-fields field)
      (filter-configuration-fields home-bash-configuration-fields
				   (list field)))

    (define (serialize-field field)
      (serialize-configuration
       config
       (filter-fields field)))

    (define* (file-if-not-empty field #:optional (extra-content #f))
      (let ((file-name (symbol->string field))
	    (field-obj (car (filter-fields field))))
	(if (or extra-content
		(not (null? ((configuration-field-getter field-obj) config))))
	    `(,(object->snake-case-string file-name)
	      ,(mixed-text-file
		(object->snake-case-string file-name)
		(if extra-content extra-content "")
		(serialize-field field)))
	    '())))

    (filter
     (compose not null?)
     `(("bash_profile"
	,(mixed-text-file
	  "bash_profile"
	  "\
  (define (filter-fields field)
    (filter-configuration-fields home-bash-configuration-fields
                                 (list field)))

  (define (serialize-field field)
    (serialize-configuration
     config
     (filter-fields field)))

  (define* (file-if-not-empty field #:optional (extra-content #f))
    (let ((file-name (symbol->string field))
          (field-obj (car (filter-fields field))))
      (if (or extra-content
              (not (null? ((configuration-field-getter field-obj) config))))
          `(,(object->snake-case-string file-name)
            ,(mixed-text-file
              (object->snake-case-string file-name)
              (if extra-content extra-content "")
              (serialize-field field)))
          '())))

  (filter
   (compose not null?)
   `(("bash_profile"
      ,(mixed-text-file
        "bash_profile"
        "\
# Setups system and user profiles and related variables
# /etc/profile will be sourced by bash automatically
# Setups home environment profile
@@ -342,14 +360,15 @@ source ~/.profile
# Honor per-interactive-shell startup file
if [ -f ~/.bashrc ]; then . ~/.bashrc; fi\n
"
	  (serialize-field 'bash-profile)))

       ,@(list (file-if-not-empty
		'bashrc
		(if (home-bash-configuration-guix-defaults? config)
		    guix-bashrc
		    #f))
	       (file-if-not-empty 'bash-logout)))))
        (serialize-field 'bash-profile)
        (serialize-field 'environment-variables)))

     ,@(list (file-if-not-empty
              'bashrc
              (if (home-bash-configuration-guix-defaults? config)
                  guix-bashrc
                  #f))
             (file-if-not-empty 'bash-logout)))))

(define (add-bash-packages config)
  (list (home-bash-configuration-package config)))

base-commit: 63009eda856a189c8760f93652d6c1dc47fc6feb
-- 
2.31.1