~abcdw/rde-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

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

Details
Message ID
<bebbdf2dafe4bfb030b0b471eefe708e182d0369.1622884500.git.public@yoctocell.xyz>
DKIM signature
pass
Download raw message
Patch: +57 -38
* 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
Details
Message ID
<878s3jgss2.fsf@trop.in>
In-Reply-To
<bebbdf2dafe4bfb030b0b471eefe708e182d0369.1622884500.git.public@yoctocell.xyz> (view parent)
DKIM signature
missing
Download raw message
>  (define (serialize-boolean field-name val) "")
> +(define (serialize-alist field-name val)
I think serialize-env-vars[-alist] would be more descriptive.
> +  (append-map
> +   (match-lambda
> +     ((key . #f)
> +      "")
> +     ((key . #t)
> +      #~(string-append "export " #$key "\n"))
> +     ((key . value)
> +      #~(string-append "export " #$key "=" #$value "\n")))
> +   val))
serialize function should return a string or string value gexp, because
you use it as an argument to mixed-text-file function.


Fixed the bug and applied the patch.  

I think environment-variables field can be useful, but next time,
please, add at least some brief motivation for changes.  It will make it
easier understand the intent and validity of the patch.

Thank you!)
Details
Message ID
<878s3jqk69.fsf@yoctocell.xyz>
In-Reply-To
<878s3jgss2.fsf@trop.in> (view parent)
DKIM signature
pass
Download raw message
On Wed, Jun 09 2021, Andrew Tropin wrote:

>>  (define (serialize-boolean field-name val) "")
>> +(define (serialize-alist field-name val)
>
> I think serialize-env-vars[-alist] would be more descriptive.

Indeed, I also have a WIP patch for Fish, so I will probably change it
to ‘serialize-posix-env-vars’.

>> +  (append-map
>> +   (match-lambda
>> +     ((key . #f)
>> +      "")
>> +     ((key . #t)
>> +      #~(string-append "export " #$key "\n"))
>> +     ((key . value)
>> +      #~(string-append "export " #$key "=" #$value "\n")))
>> +   val))
> serialize function should return a string or string value gexp, because
> you use it as an argument to mixed-text-file function.

Good catch, everthing did work when I was testing it though, not sure
why that would be the case.

> I think environment-variables field can be useful, but next time,
> please, add at least some brief motivation for changes.  It will make it
> easier understand the intent and validity of the patch.

Will keep that in mind next time.  I also think that having a ‘aliases’
field would be useful, it is something that basically everyone would
use.  It would also make it easier to switch from a POSIX compliant
shell to something like Fish, you just copy your alist of aliases, and
Guix Home will do the serialization for you.
Reply to thread Export thread (mbox)