The memoize function is not a pretty thing in terms of implementation, but it's exactly what we need to solve this UX problem and performance problem. Without this, every distinct `withSystem` call will cause a re-evaluation of the `perSystem` module, which is inefficient. Now, it's a one-time 13KB and length(system) attribute lookups: negligible compared to any instantiations and such. Nix doesn't offer memoization for functions yet, so this is the best we can do.
10 lines
354 B
Nix
10 lines
354 B
Nix
# Ad hoc manual test dependent on observing side effects
|
|
let
|
|
lib = import ~/src/nixpkgs-master/lib;
|
|
inherit (import ./memoize.nix { inherit lib; }) memoizeStr;
|
|
# Don't use this in the wild, it's too expensive!
|
|
printOnce = memoizeStr (x: builtins.trace "computing f ${lib.strings.escapeNixString x}" x);
|
|
in
|
|
{
|
|
inherit printOnce memoizeStr lib;
|
|
}
|