From 5a8cc1e51450ffd73403fda1bda221ee66b8c93f Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Thu, 10 Dec 2020 15:41:49 +0100 Subject: [PATCH] stdexp: Run python snippets and import the result --- garlic/stdexp.nix | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/garlic/stdexp.nix b/garlic/stdexp.nix index cb208f7..bb386ef 100644 --- a/garlic/stdexp.nix +++ b/garlic/stdexp.nix @@ -5,6 +5,9 @@ , targetMachine , garlicTools , bsc +, writeTextFile +, runCommandLocal +, python }: with stdenv.lib; @@ -113,4 +116,19 @@ rec { units = genUnits { inherit configs pipeline; }; in buildTrebuchet units; + + # Runs a python script and the standard output is directly imported as + # nix code + printPython = code: + let + p = writeTextFile { + name = "python-script"; + text = '' + from math import * + ${code} + ''; + }; + in + import (runCommandLocal "a" { buildInputs = [ python ]; } '' + python ${p} > $out''); }