mirror of
https://github.com/aviallon/nixos-lib.git
synced 2026-04-05 17:27:50 +00:00
[Lib/Debug] init with traceValWithPrefix and toPretty
Easier custom traces!
This commit is contained in:
parent
2be5863af8
commit
7bd2eed8ca
2 changed files with 23 additions and 0 deletions
22
lib/debug.nix
Normal file
22
lib/debug.nix
Normal file
|
|
@ -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
|
||||
;
|
||||
}
|
||||
|
|
@ -11,5 +11,6 @@ let
|
|||
optimizations = callLibs ./optimizations.nix;
|
||||
attrsets = callLibs ./attrsets.nix;
|
||||
types = callLibs ./types.nix;
|
||||
debug = callLibs ./debug.nix;
|
||||
});
|
||||
in myLib
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue