Add "guix pull".
[jackhill/guix/guix.git] / scripts / guix.in
CommitLineData
e49951eb
MW
1#!@GUILE@ -s
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.
f651b477
LC
25(use-modules (ice-9 regex)
26 (srfi srfi-26))
e49951eb
MW
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 ("datarootdir" . "@datarootdir@")
34 ("guilemoduledir" . "@guilemoduledir@")))
35 (var-ref-regexp (make-regexp "\\$\\{([a-z]+)\\}")))
36 (define (expand-var-ref match)
37 (lookup (match:substring match 1)))
38 (define (expand str)
39 (regexp-substitute/global #f var-ref-regexp str
40 'pre expand-var-ref 'post))
41 (define (lookup name)
42 (expand (assoc-ref config name)))
43 lookup))
44
45 (define (maybe-augment-load-paths!)
46 (unless (getenv "GUIX_UNINSTALLED")
47 (let ((module-dir (config-lookup "guilemoduledir")))
48 (push! module-dir %load-path)
f651b477
LC
49 (push! module-dir %load-compiled-path))
50 (let ((updates-dir (and=> (or (getenv "XDG_CONFIG_HOME")
51 (and=> (getenv "HOME")
52 (cut string-append <> "/.config")))
53 (cut string-append <> "/guix/latest"))))
54 (when (file-exists? updates-dir)
55 (push! updates-dir %load-path)
56 (push! updates-dir %load-compiled-path)))))
e49951eb
MW
57
58 (define (run-guix-main)
59 (let ((guix-main (module-ref (resolve-interface '(guix ui))
60 'guix-main)))
61 (apply guix-main (command-line))))
62
63 (maybe-augment-load-paths!)
64 (run-guix-main))