build: Add 'as-derivation' target.
[jackhill/guix/guix.git] / build-aux / compile-as-derivation.scm
CommitLineData
2cfc8d69
LC
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2018 Ludovic Courtès <ludo@gnu.org>
3;;;
4;;; This file is part of GNU Guix.
5;;;
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.
10;;;
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.
15;;;
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/>.
18
19;; Build Guix using Guix.
20
21(use-modules (srfi srfi-26))
22
23;; Add ~/.config/guix/latest to the search path.
24(add-to-load-path
25 (and=> (or (getenv "XDG_CONFIG_HOME")
26 (and=> (getenv "HOME")
27 (cut string-append <> "/.config")))
28 (cut string-append <> "/guix/latest")))
29
30(use-modules (guix) (guix ui)
31 (guix git-download)
32 (ice-9 match))
33
34(match (command-line)
35 ((program source)
36 (with-error-handling
37 (with-store store
38 (let* ((script (string-append source "/build-aux/build-self.scm"))
39 (build (primitive-load script))
40 (git? (git-predicate source)))
41 (run-with-store store
42 ;; TODO: Extract #:version and #:commit using Guile-Git.
43 (mlet* %store-monad ((source (interned-file source "guix-source"
44 #:select? git?
45 #:recursive? #t))
46 (drv (build source)))
47 (mbegin %store-monad
48 (show-what-to-build* (list drv))
49 (built-derivations (list drv))
50 (with-monad %store-monad
51 (display (derivation->output-path drv))
52 (newline)
53 (return drv))))))))))