1 ;;; Guix --- Nix package management from Guile. -*- coding: utf-8 -*-
2 ;;; Copyright (C) 2012 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of Guix.
6 ;;; 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 ;;; 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 Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (distro)
20 #:use-module (guix packages)
21 #:use-module (ice-9 ftw)
22 #:use-module (srfi srfi-1)
23 #:use-module (srfi srfi-26)
24 #:export (find-packages-by-name))
28 ;;; General utilities for the software distribution---i.e., the modules under
33 (define _ (cut gettext <> "guix"))
35 (define %distro-module-directory
36 ;; Absolute path of the (distro ...) module root.
37 (string-append (dirname (search-path %load-path "distro.scm"))
40 (define (package-files)
41 "Return the list of files that implement distro modules."
43 (string-length (dirname %distro-module-directory)))
45 (file-system-fold (const #t) ; enter?
46 (lambda (path stat result) ; leaf
47 (if (string-suffix? ".scm" path)
48 (cons (substring path prefix-len) result)
50 (lambda (path stat result) ; down
52 (lambda (path stat result) ; up
55 (lambda (path stat errno result)
56 (format (current-error-port)
57 (_ "warning: cannot access `~a': ~a")
58 path (strerror errno))
61 %distro-module-directory
64 (define (package-modules)
65 "Return the list of modules that provide packages for the distribution."
67 (char-set-complement (char-set #\/)))
69 (filter-map (lambda (path)
70 (let ((name (map string->symbol
71 (string-tokenize (string-drop-right path 4)
73 (false-if-exception (resolve-interface name))))
76 (define* (find-packages-by-name name #:optional version)
77 "Return the list of packages with the given NAME. If VERSION is not #f,
78 then only return packages whose version is equal to VERSION."
79 (define right-package?
83 (string=? (package-name p) name)
84 (string=? (package-version p) version)))
87 (string=? (package-name p) name)))))
89 (append-map (lambda (module)
90 (filter right-package?
91 (module-map (lambda (sym var)