1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2015, 2016 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 (guix grafts)
20 #:use-module (guix records)
21 #:use-module (guix derivations)
22 #:use-module ((guix utils) #:select (%current-system))
23 #:use-module (srfi srfi-1)
24 #:use-module (srfi srfi-26)
25 #:use-module (ice-9 match)
31 graft-replacement-output
38 (define-record-type* <graft> graft make-graft
40 (origin graft-origin) ;derivation | store item
41 (origin-output graft-origin-output ;string | #f
43 (replacement graft-replacement) ;derivation | store item
44 (replacement-output graft-replacement-output ;string | #f
47 (define* (graft-derivation store drv grafts
49 (name (derivation-name drv))
50 (guile (%guile-for-build))
51 (system (%current-system)))
52 "Return a derivation called NAME, based on DRV but with all the GRAFTS
54 ;; XXX: Someday rewrite using gexps.
56 ;; List of store item pairs.
58 (($ <graft> source source-output target target-output)
59 (cons (if (derivation? source)
60 (derivation->output-path source source-output)
62 (if (derivation? target)
63 (derivation->output-path target target-output)
68 (match (derivation-outputs drv)
69 (((names . outputs) ...)
70 (map derivation-output-path outputs))))
73 (match (derivation-outputs drv)
74 (((names . outputs) ...)
79 (use-modules (guix build graft)
83 (let ((mapping ',mapping))
84 (for-each (lambda (input output)
85 (format #t "grafting '~a' -> '~a'...~%" input output)
87 (rewrite-directory input output
92 (((names . files) ...)
99 ((($ <graft> sources source-outputs targets target-outputs) ...)
100 (let ((sources (zip sources source-outputs))
101 (targets (zip targets target-outputs)))
102 (build-expression->derivation store name build
104 #:guile-for-build guile
105 #:modules '((guix build graft)
107 #:inputs `(,@(map (lambda (out)
110 ,@(append (map add-label sources)
111 (map add-label targets)))
112 #:outputs output-names
113 #:local-build? #t)))))
116 ;; The following might feel more at home in (guix packages) but since (guix
117 ;; gexp), which is a lower level, needs them, we put them here.
120 ;; Whether to honor package grafts by default.
123 (define (set-grafting enable?)
124 "This monadic procedure enables grafting when ENABLE? is true, and disables
125 it otherwise. It returns the previous setting."
127 (values (%graft? enable?) store)))
129 ;;; grafts.scm ends here