1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org>
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/>.
19 (define-module (gnu packages)
20 #:use-module (guix packages)
21 #:use-module (guix utils)
22 #:use-module (ice-9 ftw)
23 #:use-module (srfi srfi-1)
24 #:use-module (srfi srfi-26)
25 #:use-module (srfi srfi-39)
26 #:export (search-patch
27 search-bootstrap-binary
29 %bootstrap-binaries-path
31 find-packages-by-name))
35 ;;; General utilities for the software distribution---i.e., the modules under
36 ;;; (gnu packages ...).
40 (define _ (cut gettext <> "guix"))
42 ;; By default, we store patches and bootstrap binaries alongside Guile
43 ;; modules. This is so that these extra files can be found without
44 ;; requiring a special setup, such as a specific installation directory
45 ;; and an extra environment variable. One advantage of this setup is
46 ;; that everything just works in an auto-compilation setting.
50 (map (cut string-append <> "/gnu/packages/patches")
53 (define %bootstrap-binaries-path
55 (map (cut string-append <> "/gnu/packages/bootstrap")
58 (define (search-patch file-name)
59 "Search the patch FILE-NAME."
60 (search-path (%patch-path) file-name))
62 (define (search-bootstrap-binary file-name system)
63 "Search the bootstrap binary FILE-NAME for SYSTEM."
64 (search-path (%bootstrap-binaries-path)
65 (string-append system "/" file-name)))
67 (define %distro-module-directory
68 ;; Absolute path of the (gnu packages ...) module root.
69 (string-append (dirname (search-path %load-path "gnu/packages.scm"))
72 (define (package-files)
73 "Return the list of files that implement distro modules."
76 (dirname (dirname (search-path %load-path "gnu/packages.scm")))))
78 (file-system-fold (const #t) ; enter?
79 (lambda (path stat result) ; leaf
80 (if (string-suffix? ".scm" path)
81 (cons (substring path prefix-len) result)
83 (lambda (path stat result) ; down
85 (lambda (path stat result) ; up
88 (lambda (path stat errno result)
89 (format (current-error-port)
90 (_ "warning: cannot access `~a': ~a~%")
91 path (strerror errno))
94 %distro-module-directory
97 (define (package-modules)
98 "Return the list of modules that provide packages for the distribution."
100 (char-set-complement (char-set #\/)))
102 (filter-map (lambda (path)
103 (let ((name (map string->symbol
104 (string-tokenize (string-drop-right path 4)
106 (false-if-exception (resolve-interface name))))
109 (define (fold-packages proc init)
110 "Call (PROC PACKAGE RESULT) for each available package, using INIT as
111 the initial value of RESULT."
112 (fold (lambda (module result)
113 (fold (lambda (var result)
118 (module-map (lambda (sym var)
119 (false-if-exception (variable-ref var)))
124 (define* (find-packages-by-name name #:optional version)
125 "Return the list of packages with the given NAME. If VERSION is not #f,
126 then only return packages whose version is equal to VERSION."
127 (define right-package?
130 (and (string=? (package-name p) name)
131 (string=? (package-version p) version)))
133 (string=? (package-name p) name))))
135 (fold-packages (lambda (package result)
136 (if (right-package? package)
137 (cons package result)