New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib/debug.nix overhaul #38368
lib/debug.nix overhaul #38368
Conversation
8b29d89
to
e96069d
Compare
I think it would be nice to have a consistent write-up (or at least a reference entry) on how to use these functions, not only in the comment field above the code but in the manual itself. This is related to NixOS/nix#701 and |
@makefu I can mention the debug module in the manual (similar to how generators is mentioned), but would rather not duplicate the docstrings (because that will go out of sync sooner rather than later). If there’s a debugging tutorial, it should most likely go into a new chapter of the nix pills, which have been designated as our official tutorial as far as I can see. |
@Profpatsch For newcomers that kind of "documentation" is far from optimal. When you start with nix and nixpkgs it is not very obvious to look for solutions inside the implementation source code. IMHO the nixpkgs |
lib/default.nix
Outdated
@@ -117,7 +117,7 @@ let | |||
traceXMLVal traceXMLValMarked traceSeq traceSeqN traceValSeq | |||
traceValSeqFn traceValSeqN traceValSeqNFn traceShowVal | |||
traceShowValMarked showVal traceCall traceCall2 traceCall3 | |||
traceValIfNot runTests testAllTrue strict traceCallXml | |||
traceValIfNot runTests testAllTrue traceCallXml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs release notes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
lib/debug.nix
Outdated
@@ -56,19 +56,25 @@ rec { | |||
traceShowVal = x: trace (showVal x) x; | |||
traceShowValMarked = str: x: trace (str + showVal x) x; | |||
attrNamesToStr = a: lib.concatStringsSep "; " (map (x: "${x}=") (attrNames a)); | |||
showVal = x: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It isn't clear to me that traceSeqN is an improvement over showVal for this use case. Can you provide some examples of the two's output?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
showVal
displays the value with one layer of depth. traceValSeqN 1
does the same, traceValSeqN 2
does the same for a depth of two layers and so forth.
To be fair, the display is different, but I don’t think there is any information in showVal
that cannot be seen in the output of traceValSeqN
.
lib/debug.nix
Outdated
trace ( "Warning: `traceXMLValMarked` is deprecated " | ||
+ "and will be removed in the next release." ) | ||
(trace (str + builtins.toXML x) x); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These need release notes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
nixos/modules/misc/nixpkgs.nix
Outdated
@@ -33,7 +33,7 @@ let | |||
configType = mkOptionType { | |||
name = "nixpkgs-config"; | |||
description = "nixpkgs config"; | |||
check = traceValIfNot isConfig; | |||
check = x: if isConfig x then true else lib.traceSeqN 1 x false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the named one, actually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It’s locally let
-named in the rebased commit.
@makefu Added an initial section to the manual in the last commit. It is more of a stub for now (but at least users now find something when they search for debug (in the right manual)). |
I think all the functions which have been deprecated need:
|
1817a0f
to
d136321
Compare
Added release notes & replacement instructions in the last commit. |
<section xml:id="sec-debug"> | ||
<title>Debugging Nix Expressions</title> | ||
|
||
<para>Nix is a unityped, dynamic language, this means every value can |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unityped or untyped?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neither of those are true 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shlevy Hm, why is nix not unityped?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[]
and {}
are of different types. The fact that those are checked at eval time (which, FWIW, can be seen as compile time with respect to the underlying .drv
outputs...) doesn't make them not typed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, well, I see eval time more as execution time.
Being able to modify the value on-the-fly before printing is very useful in practice.
The grace period was long enough.
The code is re-implemented in terms of `generators.toPretty`, but is strictly less general than `traceValSeqN`, so we deprecate it.
`attrNamesToStr` is very specific (and pretty trivial), so it doesn’t make sense to have it in the library. `traceXMLVal(Marked)` are just a builtin and `trace` and not very useful in general (trace output should not be parsed anyway).
The function is only used in exactly one module and overly specific (`c` must be a true predicate for `x`, if not, a specific trace is called).
The function isn’t used anywhere and `addErrorContext` is an undocumented builtin. The builtin is explicitely qualified at its two uses in the module system.
Incompletely documented, and a FIXME/bug that has been there for years.
Reason: has overhauled the module quite substantially.
It is more of a stub for now, but at least points to the right file.
for every deprecated function.
d136321
to
0d3d0fd
Compare
I rebased it to remove the release note merge conflicts. |
Merging because no further feedback. |
traceShowVal traceShowValMarked attrNamesToStr showVal traceXMLVal traceXMLValMarked traceCall traceCall2 traceCall3 traceValIfNot addErrorContextToAttrs traceCallXml they were deprecated in NixOS#38368
The
debug
module is very useful for day-to-day nix programming, but hasn’t seen a lot of care and aquired quite a lot of cruft.Main changes:
*Val*Fn
group of functionsstrict
functionshowVal
group of functions becausetraceSeqN
should be strictly more generalXml
-group of functions, because they are mostly trivial and/or overly specifictraceValIfNot
andaddErrorContextToAttrs
More detailed reasoning is included in each commit description.