[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug#28251] [PATCH 0/3] Add generic JSON importer
From: |
Ricardo Wurmus |
Subject: |
[bug#28251] [PATCH 0/3] Add generic JSON importer |
Date: |
Sun, 27 Aug 2017 17:58:20 +0200 |
Hi Guix,
this patch set adds a somewhat unusual importer. Assume we have a file
"package.json" with the following contents:
--8<---------------cut here---------------start------------->8---
{
"name": "hello",
"version": "2.10",
"source": {
"method": "url-fetch",
"uri": "mirror://gnu/hello/hello-2.10.tar.gz",
"sha256": {
"base32": "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"
}
}
"build-system": "gnu",
"home-page": "https://www.gnu.org/software/hello/",
"synopsis": "Hello, GNU world: An example GNU package",
"description": "It really works.",
"license": "GPL-3.0+",
"inputs": ["address@hidden", "ghc-pandoc", "address@hidden"]
}
--8<---------------cut here---------------end--------------->8---
Let’s run the new “json” importer on this file:
--8<---------------cut here---------------start------------->8---
$ ./pre-inst-env guix import json package.json
(package
(name "hello")
(version "2.10")
(source
(origin
(uri (string-append
"mirror://gnu/hello/hello-2.10.tar.gz"))
(method url-fetch)
(sha256
(base32
"0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"))))
(build-system r-build-system)
(inputs
`(("r-minimal"
,(@ (gnu packages statistics) r-minimal))
("ghc-pandoc"
,(@ (gnu packages haskell) ghc-pandoc))
("samtools"
,(@ (gnu packages bioinformatics) samtools-0.1))))
(home-page "https://www.gnu.org/software/hello/")
(synopsis
"Hello, GNU world: An example GNU package")
(description "It really works.")
(license gpl3+))
--8<---------------cut here---------------end--------------->8---
What you don’t see here is that the JSON importer internally creates a
package object, which could already be built (e.g. from within the REPL)
— without having to write it to a file first and setting
GUIX_PACKAGE_PATH.
What is this good for? Users could create simple Guix packages for
their own immature projects using a syntax that they may be more
familiar with and generate a proper Scheme package definition from it to
allow other people to install it. For more complicated packages they
would, of course, be better served by using the usual Scheme syntax for
package definitions.
To make the importer behave like all other importers, we use the new
“package->code” procedure, which takes a package and generates the code,
which would create an equivalent package object when evaluated.
There are some minor problems with “package->code”, which are marked
with FIXME comments. We probably shouldn’t print out “(@ (gnu packages
statistics) r-minimal)” and instead let “package->code” return two
values: the package code and a list of modules needed to evaluate it.
What do you think? Terrible? Exciting? Both? *raises hand*
Documentation of this importer is missing because I’m not sure if this
is the best way of doing this. Let’s discuss!
~~ Ricardo
Ricardo Wurmus (3):
packages: Add package->code.
import: Add generic data to package converter.
import: Add JSON importer.
guix/import/utils.scm | 77 ++++++++++++++++++++++++-
guix/packages.scm | 131 +++++++++++++++++++++++++++++++++++++++++++
guix/scripts/import.scm | 2 +-
guix/scripts/import/json.scm | 101 +++++++++++++++++++++++++++++++++
4 files changed, 309 insertions(+), 2 deletions(-)
create mode 100644 guix/scripts/import/json.scm
--
2.14.1
- [bug#28251] [PATCH 0/3] Add generic JSON importer,
Ricardo Wurmus <=