From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41758) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlzxp-0006qF-9b for guix-patches@gnu.org; Sun, 27 Aug 2017 11:59:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dlzxm-0006IQ-7C for guix-patches@gnu.org; Sun, 27 Aug 2017 11:59:05 -0400 Received: from debbugs.gnu.org ([208.118.235.43]:49317) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dlzxm-0006IM-3j for guix-patches@gnu.org; Sun, 27 Aug 2017 11:59:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dlzxl-00017Q-PX for guix-patches@gnu.org; Sun, 27 Aug 2017 11:59:01 -0400 Subject: [bug#28251] [PATCH 0/3] Add generic JSON importer Resent-Message-ID: Received: from eggs.gnu.org ([2001:4830:134:3::10]:41741) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlzxK-0006og-S9 for guix-patches@gnu.org; Sun, 27 Aug 2017 11:58:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dlzxH-0006Dd-HX for guix-patches@gnu.org; Sun, 27 Aug 2017 11:58:34 -0400 Received: from sender-of-o51.zoho.com ([135.84.80.216]:21029) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dlzxH-0006DJ-9W for guix-patches@gnu.org; Sun, 27 Aug 2017 11:58:31 -0400 From: Ricardo Wurmus Date: Sun, 27 Aug 2017 17:58:20 +0200 Message-Id: <20170827155820.28812-1-rekado@elephly.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 28251@debbugs.gnu.org Cc: Ricardo Wurmus 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": ["r-minimal@3", "ghc-pandoc", "samtools@0"] } --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