stdexp: Run python snippets and import the result

This commit is contained in:
Rodrigo Arias Mallo 2020-12-10 15:41:49 +01:00
parent 7d4db6b6de
commit 5a8cc1e514

View File

@ -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'');
}