Nix has a rarely used
builtins.exec which allows to execute an external program and capture its output on the eval phase
It has many benefits which otherwise would require import-from-derivation or won’t be possible at all.
A nice summary of the use cases by @shlevy is here https://github.com/NixOS/nix/commit/0bb8db257d98a32abde759f4d07d28b5178bd3bf
The problem is: if half of my use cases, the number of required
builtins.exec invocations is quadratic to the number of required results.
One example is reading keys for Tinc or generate a random key and add it to git if it is a new machine and does not have a key yet.
if there are 100 machines, each has a key and each key is included in 99 closures of other machines.
So there are 9900 invocations of
builtins.exec when compiling nixops forest of system closures, although there are only 100 unique keys (thanks to Nix’s referential transparency, if one could say that about something so inpure as
I wonder, if it possible to memoize results of
builtins.exec, or generally, memoize anything for the time of the Nix evaluation phase? It could be useful for other functions too,
I have some (probably false) memories that there was a commit in the Nix history adding something like
builtins.memo or a singleton hash table which has been reverted afterwards, but I cannot find it…