Commit | Line | Data |
---|---|---|
457f60fa AK |
1 | ;;; GNU Guix --- Functional package management for GNU |
2 | ;;; Copyright © 2014 Alex Kost <alezost@gmail.com> | |
3 | ;;; | |
4 | ;;; This file is part of GNU Guix. | |
5 | ;;; | |
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. | |
10 | ;;; | |
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. | |
15 | ;;; | |
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/>. | |
18 | ||
19 | ;;; Commentary: | |
20 | ||
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. | |
23 | ||
24 | ;;; Code: | |
25 | ||
26 | (use-modules (ice-9 regex) | |
27 | (srfi srfi-26)) | |
28 | ||
29 | (define %guix-dir) | |
30 | ||
31 | ;; The code is taken from ‘guix’ executable script | |
32 | (define (set-paths!) | |
33 | (define-syntax-rule (push! elt v) (set! v (cons elt v))) | |
34 | ||
35 | (define config-lookup | |
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))) | |
41 | (define (expand str) | |
42 | (regexp-substitute/global #f var-ref-regexp str | |
43 | 'pre expand-var-ref 'post)) | |
44 | (define (lookup name) | |
45 | (expand (assoc-ref config name))) | |
46 | lookup)) | |
47 | ||
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-compiled-path) | |
54 | (if (and updates-dir (file-exists? updates-dir)) | |
55 | (begin | |
56 | (set! %guix-dir updates-dir) | |
57 | (push! updates-dir %load-path) | |
58 | (push! updates-dir %load-compiled-path)) | |
59 | (set! %guix-dir module-dir)))) | |
60 | ||
61 | (set-paths!) | |
62 | ||
63 | (load-from-path "guix-main") | |
64 |