From 22d7c08dc506f74803b7c61c6cbf156dfe844f02 Mon Sep 17 00:00:00 2001 From: zimbatm Date: Sun, 28 Feb 2016 16:35:27 +0000 Subject: [PATCH 1/2] lib.trivial: add a new importJSON function This is meant to be used by packages who often re-generate their inputs. Producing valid JSON is easier than nix, and also garantees it's purity. --- lib/trivial.nix | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/trivial.nix b/lib/trivial.nix index cda8aa08a20..9821e3c138d 100644 --- a/lib/trivial.nix +++ b/lib/trivial.nix @@ -75,4 +75,25 @@ rec { min = x: y: if x < y then x else y; max = x: y: if x > y then x else y; + /* Reads a JSON file. It is useful to import pure data into other nix + expressions. + + Example: + + mkDerivation { + src = fetchgit (importJSON ./repo.json) + #... + } + + where repo.json contains: + + { + "url": "git://some-domain/some/repo", + "rev": "265de7283488964f44f0257a8b4a055ad8af984d", + "sha256": "0sb3h3067pzf3a7mlxn1hikpcjrsvycjcnj9hl9b1c3ykcgvps7h" + } + + */ + importJSON = path: + builtins.fromJSON (builtins.readFile path); } From 6d9cc5408909aa304cd8af25059b129c1652c26e Mon Sep 17 00:00:00 2001 From: zimbatm Date: Mon, 29 Feb 2016 13:49:29 +0000 Subject: [PATCH 2/2] build-maven: use lib.importJSON --- pkgs/build-support/build-maven.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/build-support/build-maven.nix b/pkgs/build-support/build-maven.nix index ff91828eeca..ba85428ba8c 100644 --- a/pkgs/build-support/build-maven.nix +++ b/pkgs/build-support/build-maven.nix @@ -11,7 +11,7 @@ * the project. */ infoFile: let - info = builtins.fromJSON (builtins.readFile infoFile); + info = lib.importJSON infoFile; script = writeText "build-maven-repository.sh" '' ${lib.concatStrings (map (dep: let