1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014 Alex Kost <alezost@gmail.com>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
21 ;; This is an auxiliary file for the Emacs UI. It is used to add Guix
22 ;; directories to path variables and to load the main code.
26 (use-modules (ice-9 regex)
31 ;; The code is taken from ‘guix’ executable script
33 (define-syntax-rule (push! elt v) (set! v (cons elt v)))
36 (let ((config '(("prefix" . "@prefix@")
37 ("guilemoduledir" . "@guilemoduledir@")))
38 (var-ref-regexp (make-regexp "\\$\\{([a-z]+)\\}")))
39 (define (expand-var-ref match)
40 (lookup (match:substring match 1)))
42 (regexp-substitute/global #f var-ref-regexp str
43 'pre expand-var-ref 'post))
45 (expand (assoc-ref config name)))
48 (let ((module-dir (config-lookup "guilemoduledir"))
49 (updates-dir (and=> (or (getenv "XDG_CONFIG_HOME")
50 (and=> (getenv "HOME")
51 (cut string-append <> "/.config")))
52 (cut string-append <> "/guix/latest"))))
53 (push! module-dir %load-path)
54 (push! module-dir %load-compiled-path)
55 (if (and updates-dir (file-exists? updates-dir))
57 (set! %guix-dir updates-dir)
58 (push! updates-dir %load-path)
59 (push! updates-dir %load-compiled-path))
60 (set! %guix-dir module-dir))))
64 (load-from-path "guix-main")