diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm index 933f7d8ee57af6559dc81399516a2ac01ff24502..9e433dd191ccc17c1cfce6d882f041dde3c17188 100644 --- a/guix/scripts/package.scm +++ b/guix/scripts/package.scm @@ -384,7 +384,7 @@ (define* (search-path-environment-variables entries profile (append-map manifest-entry-search-paths entries)))) (filter-map (match-lambda ((variable . value) - (format #f "export ~a=\"~a\"" variable value))) + (environment-variable-definition variable value))) (evaluate-search-paths search-paths profile getenv)))) (define (display-search-paths entries profile) diff --git a/guix/search-paths.scm b/guix/search-paths.scm index b17f5acd5d2a6eb2addbd0eaa1da8e1e0edebbd6..7957c8824157d47b5597cafaba866eaf1c0626d4 100644 --- a/guix/search-paths.scm +++ b/guix/search-paths.scm @@ -33,7 +33,8 @@ (define-module (guix search-paths) search-path-specification->sexp sexp->search-path-specification - evaluate-search-paths)) + evaluate-search-paths + environment-variable-definition)) ;;; Commentary: ;;; @@ -144,4 +145,26 @@ (define search-path-definition (filter-map search-path-definition search-paths)) +(define* (environment-variable-definition variable value + #:key + (kind 'exact) + (separator ":")) + "Return a the definition of VARIABLE to VALUE in Bash syntax: + +KIND can be either 'exact (return the definition of VARIABLE=VALUE), +'prefix (return the definition where VALUE is added as a prefix to VARIABLE's +current value), or 'suffix (return the definition where VALUE is added as a +suffix to VARIABLE's current value.) In the case of 'prefix and 'suffix, +SEPARATOR is used as the separator between VARIABLE's current value and its +prefix/suffix." + (match kind + ('exact + (format #f "export ~a=\"~a\"" variable value)) + ('prefix + (format #f "export ~a=\"~a${~a:+~a}$~a\"" + variable value variable separator variable)) + ('suffix + (format #f "export ~a=\"$~a${~a:+~a}~a\"" + variable variable variable separator value)))) + ;;; search-paths.scm ends here