[Nix-dev] Dynamic Dependency Management by Calling External Programs from Nix

Shea Levy shea at shealevy.com
Wed Oct 26 16:33:20 CEST 2011


Hi Peter,

On 10/25/11 1:15 PM, Peter Simons wrote:
> Hi Shea,
>
>   >  1. builtins.exec. This builtin would take a string and would evaluate
>   >     to a string. It would essentially call system() on its argument and
>   >     evaluate to the output put to stdout by that command.
>
> I am not expert in these matters, so please bear with me if this is
> stupid question, but I wonder in what way exec would be different from
> runCommand? How do these two functions compare?

runCommand runs a command at _realisation_ time: you're already in a 
builder, and you can't use the outputs of the command you ran in a nix 
expression itself.

builtins.exec, on the other hand, would run at _instantiation_ time. So 
you can use the outputs in a nix expression, and in particular to create 
derivations on-the-fly.

For example, suppose I had a function that takes a haskell package name 
as a string and evaluates to a derivation to build that package with all 
of the dependencies properly built as separate derivations that are 
inputs to the evaluated-to derivation. To do the dependency management 
right, I would want to check if the current package has any dependencies 
and, if it does, recursively call the function with the name of the 
dependency. How do I get that name? I can't call buildHaskell 
${runCommand dep {} findFirstDependency} because that will just evaluate 
to buildHaskell /nix/store/whatever-dep which is obviously not what we 
want. buildHaskell (builtins.exec findFirstDependency) would do the 
trick, though.

That being said, I much prefer the builtins.readFile extension over 
builtins.exec.

> Take care,
> Peter
>
> _______________________________________________
> nix-dev mailing list
> nix-dev at lists.science.uu.nl
> http://lists.science.uu.nl/mailman/listinfo/nix-dev

~Shea


More information about the nix-dev mailing list