[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Guix and Emacs Integration for Polyglot Development
From: |
Jan Nieuwenhuizen |
Subject: |
Re: Guix and Emacs Integration for Polyglot Development |
Date: |
Thu, 13 Sep 2018 22:45:19 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) |
Ludovic Courtès writes:
> In all modesty ;-) I think the API is rather good:
>
> scheme@(guile-user)> ,use(guix profiles)
> scheme@(guile-user)> (profile-search-paths "/home/ludo/.guix-profile")
> $11 = ((#<<search-path-specification> variable: "PATH" files: ("bin" "sbin")
> separator: ":" file-type: directory file-pattern: #f> .
> "/home/ludo/.guix-profile/bin:/home/ludo/.guix-profile/sbin")
> (#<<search-path-specification> variable: "PYTHONPATH" files:
> ("lib/python3.6/site-packages") separator: ":" file-type: directory
> file-pattern: #f> . "/home/ludo/.guix-profile/lib/python3.6/site-packages") …
Whoa, that helps! Is it just me who is so dense -- I really think this
REPL'y power of Guix is much under-appreciated and would deserve
more attention.
So, what about (thanks to Ricardo via #guile irc and wasamasa via #emacs)
--8<---------------cut here---------------start------------->8---
(defun guix-switch-profile (&optional profile)
"Switch Emacs' environment to PROFILE. PROFILE can be a named
profile (like ~/.guix-profile, ~/.config/guix/work) or an
environment (like: echo $GUIX_ENVIRONMENT)."
(interactive "fprofile: ")
(lexical-let* ((guix-program
`(begin
(use-modules (ice-9 match)
(guix profiles)
(guix search-paths))
(let ((specs (profile-search-paths ,(expand-file-name
profile))))
(map
(match-lambda ((spec . dir)
(list (search-path-specification-variable
spec)
(or
(search-path-specification-separator spec) "")
dir)))
specs))))
(guix-output (guix-eval (format "%S" guix-program)))
(profile-sexp (car (read-from-string (car guix-output)))))
(mapcar*
(lambda (variable separator path)
(lexical-let ((value (cond ((string-empty-p separator) path)
((getenv variable) (concat path separator
(getenv variable)))
(t path))))
(setenv variable value)))
(mapcar #'car profile-sexp)
(mapcar #'cadr profile-sexp)
(mapcar #'caddr profile-sexp))))
--8<---------------cut here---------------end--------------->8---
and where to put this?
janneke