final: prev: let lib = final; in with lib; { generators = with final.generators; prev.generators // { toPreserves = { }@args: v: let concatItems = lib.strings.concatStringsSep " "; in if isAttrs v then "{ ${ concatItems (lib.attrsets.mapAttrsToList (key: val: "${key}: ${toPreserves args val}") v) } }" else if isList v then "[ ${concatItems (map (toPreserves args) v)} ]" else if isBool v then (if v then "#t" else "#f") else if isFunction v then abort "generators.toPreserves: cannot convert a function to Preserves" else if isNull v then "null" else builtins.toJSON v; }; }