diff --git a/lib/debug.nix b/lib/debug.nix new file mode 100644 index 0000000..1145ada --- /dev/null +++ b/lib/debug.nix @@ -0,0 +1,22 @@ +{ lib, myLib }: +with lib; +rec { + toPretty = depth: x: + # Stolen from: https://github.com/teto/nixpkgs/blob/6f098631f6f06b93c17f49abdf677790e017778d/lib/debug.nix#L109C5-L117C30 + let + snip = v: if isList v then noQuotes "[…]" v + else if isAttrs v then noQuotes "{…}" v + else v; + noQuotes = str: v: { __pretty = const str; val = v; }; + modify = n: fn: v: if (n == 0) then fn v + else if isList v then map (modify (n - 1) fn) v + else if isAttrs v then mapAttrs + (const (modify (n - 1) fn)) v + else v; + in lib.generators.toPretty { allowPrettyValues = true; } (modify depth snip x); + + traceValWithPrefix = prefix: value: + #trace "traceValWithPrefix 'prefix': ${prefix}" value + trace "${prefix}: ${toPretty 2 value}" value + ; +} diff --git a/lib/default.nix b/lib/default.nix index 1d322c8..a7437a2 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -11,5 +11,6 @@ let optimizations = callLibs ./optimizations.nix; attrsets = callLibs ./attrsets.nix; types = callLibs ./types.nix; + debug = callLibs ./debug.nix; }); in myLib