guix.in 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. ;; IMPORTANT: We must avoid loading any modules from Guix here,
  22. ;; because we need to adjust the guile load paths first.
  23. ;; It's okay to import modules from core Guile though.
  24. (use-modules (ice-9 regex)
  25. (srfi srfi-26))
  26. (let ()
  27. (define-syntax-rule (push! elt v) (set! v (cons elt v)))
  28. (define config-lookup
  29. (let ((config '(("prefix" . "@prefix@")
  30. ("exec_prefix" . "@exec_prefix@")
  31. ("datarootdir" . "@datarootdir@")
  32. ("guilemoduledir" . "@guilemoduledir@")
  33. ("guileobjectdir" . "@guileobjectdir@")
  34. ("localedir" . "@localedir@")))
  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. (define (maybe-augment-load-paths!)
  45. (unless (getenv "GUIX_UNINSTALLED")
  46. (let ((module-dir (config-lookup "guilemoduledir"))
  47. (object-dir (config-lookup "guileobjectdir")))
  48. (push! module-dir %load-path)
  49. (push! object-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 (and updates-dir (file-exists? updates-dir))
  55. ;; XXX: Currently 'guix pull' puts both .scm and .go files in
  56. ;; UPDATES-DIR.
  57. (push! updates-dir %load-path)
  58. (push! updates-dir %load-compiled-path)))))
  59. (define (run-guix-main)
  60. (let ((guix-main (module-ref (resolve-interface '(guix ui))
  61. 'guix-main)))
  62. (bindtextdomain "guix" (config-lookup "localedir"))
  63. (bindtextdomain "guix-packages" (config-lookup "localedir"))
  64. (apply guix-main (command-line))))
  65. (maybe-augment-load-paths!)
  66. ;; XXX: It would be more convenient to change it to:
  67. ;; (exit (run-guix-main))
  68. ;; but since the 'guix' command is not updated by 'guix pull', we cannot
  69. ;; really do it now.
  70. (run-guix-main))