distro: Add package that builds a tarball of the bootstrap Guile.
[jackhill/guix/guix.git] / distro.scm
CommitLineData
6b1891b0
LC
1;;; Guix --- Nix package management from Guile. -*- coding: utf-8 -*-
2;;; Copyright (C) 2012 Ludovic Courtès <ludo@gnu.org>
3;;;
4;;; This file is part of Guix.
5;;;
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.
10;;;
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.
15;;;
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/>.
18
19(define-module (distro)
20 #:use-module (guix packages)
800cdeef 21 #:use-module (guix utils)
6b1891b0
LC
22 #:use-module (ice-9 ftw)
23 #:use-module (srfi srfi-1)
24 #:use-module (srfi srfi-26)
800cdeef
LC
25 #:use-module (srfi srfi-39)
26 #:export (search-patch
27 %patch-directory
28 find-packages-by-name))
6b1891b0
LC
29
30;;; Commentary:
31;;;
32;;; General utilities for the software distribution---i.e., the modules under
33;;; (distro ...).
34;;;
35;;; Code:
36
37(define _ (cut gettext <> "guix"))
38
800cdeef
LC
39(define %patch-directory
40 (make-parameter
41 (or (getenv "DISTRO_PATCH_DIRECTORY")
42 (compile-time-value (getenv "DISTRO_INSTALLED_PATCH_DIRECTORY")))))
43
44(define (search-patch file-name)
45 "Search the patch FILE-NAME."
46 (search-path (list (%patch-directory)) file-name))
47
6b1891b0
LC
48(define %distro-module-directory
49 ;; Absolute path of the (distro ...) module root.
50 (string-append (dirname (search-path %load-path "distro.scm"))
1f455fdc 51 "/distro/packages"))
6b1891b0
LC
52
53(define (package-files)
54 "Return the list of files that implement distro modules."
55 (define prefix-len
1722d680 56 (string-length (dirname (search-path %load-path "distro.scm"))))
6b1891b0
LC
57
58 (file-system-fold (const #t) ; enter?
59 (lambda (path stat result) ; leaf
60 (if (string-suffix? ".scm" path)
61 (cons (substring path prefix-len) result)
62 result))
63 (lambda (path stat result) ; down
64 result)
65 (lambda (path stat result) ; up
66 result)
67 (const #f) ; skip
68 (lambda (path stat errno result)
69 (format (current-error-port)
49feac7a 70 (_ "warning: cannot access `~a': ~a~%")
6b1891b0
LC
71 path (strerror errno))
72 result)
73 '()
74 %distro-module-directory
75 stat))
76
77(define (package-modules)
78 "Return the list of modules that provide packages for the distribution."
79 (define not-slash
80 (char-set-complement (char-set #\/)))
81
82 (filter-map (lambda (path)
83 (let ((name (map string->symbol
84 (string-tokenize (string-drop-right path 4)
85 not-slash))))
86 (false-if-exception (resolve-interface name))))
87 (package-files)))
88
89(define* (find-packages-by-name name #:optional version)
90 "Return the list of packages with the given NAME. If VERSION is not #f,
91then only return packages whose version is equal to VERSION."
92 (define right-package?
93 (if version
94 (lambda (p)
95 (and (package? p)
96 (string=? (package-name p) name)
97 (string=? (package-version p) version)))
98 (lambda (p)
99 (and (package? p)
100 (string=? (package-name p) name)))))
101
102 (append-map (lambda (module)
103 (filter right-package?
104 (module-map (lambda (sym var)
105 (variable-ref var))
106 module)))
107 (package-modules)))