summaryrefslogtreecommitdiff
path: root/guix/scripts/build.scm
diff options
context:
space:
mode:
authorRicardo Wurmus <rekado@elephly.net>2017-08-27 17:41:18 +0200
committerRicardo Wurmus <rekado@elephly.net>2017-09-28 13:10:11 +0200
commitfb1db385476bc4548d3eadea93b5dd6a346839f2 (patch)
tree6c505efc758fc6ecc15c567a906d353d5ef1adb5 /guix/scripts/build.scm
parent5e892bc365a3da0d30a0982783ee2ab82ee090f8 (diff)
downloadpatches-fb1db385476bc4548d3eadea93b5dd6a346839f2.tar
patches-fb1db385476bc4548d3eadea93b5dd6a346839f2.tar.gz
import: Add JSON importer.
* doc/guix.texi (Invoking guix import): Document it. * guix/scripts/import/json.scm: New file. * Makefile.am (MODULES): Add it. * guix/scripts/import.scm (importers): Add json importer.
Diffstat (limited to 'guix/scripts/build.scm')
-rw-r--r--guix/scripts/build.scm18
1 files changed, 17 insertions, 1 deletions
diff --git a/guix/scripts/build.scm b/guix/scripts/build.scm
index 0571b874f1..3cc679c70a 100644
--- a/guix/scripts/build.scm
+++ b/guix/scripts/build.scm
@@ -1,6 +1,7 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2013 Mark H Weaver <mhw@netris.org>
+;;; Copyright © 2017 Ricardo Wurmus <rekado@elephly.net>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -31,9 +32,11 @@
#:use-module (guix monads)
#:use-module (guix gexp)
+ #:autoload (json) (json-string->scm)
#:autoload (guix http-client) (http-fetch http-get-error?)
#:use-module (ice-9 format)
#:use-module (ice-9 match)
+ #:use-module (ice-9 rdelim)
#:use-module (ice-9 vlist)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-11)
@@ -55,6 +58,10 @@
register-root
register-root*))
+;; Lazy reference to import utils to avoid cycle
+(define (lazy-util sym)
+ (module-ref (resolve-interface '(guix import utils)) sym))
+
(define %default-log-urls
;; Default base URLs for build logs.
'("http://hydra.gnu.org/log"))
@@ -606,7 +613,16 @@ build---packages, gexps, derivations, and so on."
(else
(list (specification->package spec)))))
(('file . file)
- (ensure-list (load* file (make-user-module '()))))
+ (if (string-suffix? ".json" file)
+ (begin
+ ;; Load (json) lazily to avoid hard dependency.
+ ;; TODO: doesn't work
+ (let* ((json (json-string->scm
+ (with-input-from-file file read-string)))
+ (pkg ((lazy-util 'data->guix-package)
+ ((lazy-util 'hash-table->alist) json))))
+ (ensure-list pkg)))
+ (ensure-list (load* file (make-user-module '())))))
(('expression . str)
(ensure-list (read/eval str)))
(('argument . (? derivation? drv))