From e78a8c0725cbcf3179d63f8f94ca77e7ccb345d8 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 9 Feb 2017 16:13:26 +0100 Subject: write{Jq,Python*}: use writeOut --- krebs/5pkgs/writers.nix | 63 +++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 33 deletions(-) (limited to 'krebs/5pkgs/writers.nix') diff --git a/krebs/5pkgs/writers.nix b/krebs/5pkgs/writers.nix index 6e33a6507..fe8fe5d72 100644 --- a/krebs/5pkgs/writers.nix +++ b/krebs/5pkgs/writers.nix @@ -252,17 +252,16 @@ with import ; ''; }; - writeJq = name: text: pkgs.runCommand name { - inherit text; - passAsFile = [ "text" ]; - } /* sh */ '' - name=${assert types.filename.check name; name} - - # syntax check - ${pkgs.jq}/bin/jq -f "$textPath" -n - - cp "$textPath" "$out" - ''; + writeJq = name: text: + assert (with types; either absolute-pathname filename).check name; + pkgs.writeOut (baseNameOf name) { + ${optionalString (types.absolute-pathname.check name) name} = { + check = pkgs.writeDash "jqcheck.sh" '' + exec ${pkgs.jq}/bin/jq -f "$1" -n + ''; + inherit text; + }; + }; writeJSON = name: value: pkgs.writeText name (toJSON value); @@ -275,29 +274,27 @@ with import ; ${pkgs.cabal2nix}/bin/cabal2nix ${path} > $out ''); - writePython2 = name: text: pkgs.runCommand name { - inherit text; - passAsFile = [ "text" ]; - } /* sh */ '' - name=${assert types.filename.check name; name} - - # syntax check - ${pkgs.python2}/bin/python -m py_compile "$textPath" - - cp "$textPath" "$out" - ''; - - writePython3 = name: text: pkgs.runCommand name { - inherit text; - passAsFile = [ "text" ]; - } /* sh */ '' - name=${assert types.filename.check name; name} - - # syntax check - ${pkgs.python3}/bin/python -m py_compile "$textPath" + writePython2 = name: text: + assert (with types; either absolute-pathname filename).check name; + pkgs.writeOut (baseNameOf name) { + ${optionalString (types.absolute-pathname.check name) name} = { + check = pkgs.writeDash "python2check.sh" '' + exec ${pkgs.python2}/bin/python -m py_compile "$1" + ''; + inherit text; + }; + }; - cp "$textPath" "$out" - ''; + writePython3 = name: text: + assert (with types; either absolute-pathname filename).check name; + pkgs.writeOut (baseNameOf name) { + ${optionalString (types.absolute-pathname.check name) name} = { + check = pkgs.writeDash "python3check.sh" '' + exec ${pkgs.python3}/bin/python -m py_compile "$textPath" + ''; + inherit text; + }; + }; writeSed = pkgs.makeScriptWriter "${pkgs.gnused}/bin/sed -f"; }; -- cgit v1.2.3