gnu: Add virtualgl.
[jackhill/guix/guix.git] / scripts / guix.in
1 #!@GUILE@ --no-auto-compile
2 -*- scheme -*-
3 !#
4 ;;; GNU Guix --- Functional package management for GNU
5 ;;; Copyright © 2013 Mark H Weaver <mhw@netris.org>
6 ;;;
7 ;;; This file is part of GNU Guix.
8 ;;;
9 ;;; GNU Guix is free software; you can redistribute it and/or modify it
10 ;;; under the terms of the GNU General Public License as published by
11 ;;; the Free Software Foundation; either version 3 of the License, or (at
12 ;;; your option) any later version.
13 ;;;
14 ;;; GNU Guix is distributed in the hope that it will be useful, but
15 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;;; GNU General Public License for more details.
18 ;;;
19 ;;; You should have received a copy of the GNU General Public License
20 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
21
22 ;; IMPORTANT: We must avoid loading any modules from Guix here,
23 ;; because we need to adjust the guile load paths first.
24 ;; It's okay to import modules from core Guile though.
25 (use-modules (ice-9 regex)
26 (srfi srfi-26))
27
28 (let ()
29 (define-syntax-rule (push! elt v) (set! v (cons elt v)))
30
31 (define config-lookup
32 (let ((config '(("prefix" . "@prefix@")
33 ("exec_prefix" . "@exec_prefix@")
34 ("datarootdir" . "@datarootdir@")
35 ("guilemoduledir" . "@guilemoduledir@")
36 ("guileobjectdir" . "@guileobjectdir@")
37 ("localedir" . "@localedir@")))
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 (define (maybe-augment-load-paths!)
49 (unless (getenv "GUIX_UNINSTALLED")
50 (let ((module-dir (config-lookup "guilemoduledir"))
51 (object-dir (config-lookup "guileobjectdir")))
52 (push! module-dir %load-path)
53 (push! object-dir %load-compiled-path))
54 (let ((updates-dir (and=> (or (getenv "XDG_CONFIG_HOME")
55 (and=> (getenv "HOME")
56 (cut string-append <> "/.config")))
57 (cut string-append <> "/guix/latest"))))
58 (when (and updates-dir (file-exists? updates-dir))
59 ;; XXX: Currently 'guix pull' puts both .scm and .go files in
60 ;; UPDATES-DIR.
61 (push! updates-dir %load-path)
62 (push! updates-dir %load-compiled-path)))))
63
64 (define (run-guix-main)
65 (let ((guix-main (module-ref (resolve-interface '(guix ui))
66 'guix-main)))
67 (bindtextdomain "guix" (config-lookup "localedir"))
68 (bindtextdomain "guix-packages" (config-lookup "localedir"))
69 (apply guix-main (command-line))))
70
71 (maybe-augment-load-paths!)
72
73 ;; XXX: It would be more convenient to change it to:
74 ;; (exit (run-guix-main))
75 ;; but since the 'guix' command is not updated by 'guix pull', we cannot
76 ;; really do it now.
77 (run-guix-main))