-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
{nix,lix,stdenv}: log hook information only if NIX_DEBUG >= 1; provide means to set it #331383
Conversation
grep -r -l -Z -e 'env."NIX_LOG_FD".*"2"' src | \ | ||
xargs -0 sed -i '/NIX_LOG_FD.*2/a env["NIX_DEBUG"] = "${toString withNixDebug}";' |
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.
The idea gets an ACK from me but this snippet must be refactored; it is unreadable.
Ideally, we'd have this as a build-time (or even runtime) feature in Lix.
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'm going to collect more feedback before investing the work to do that, especially if the idea itself gets mondo pushback from others. Having it work with upstream support definitely is "the right way", for sure.
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 would say that the complain of Atemu is nonsense, given that grep and xargs are usually unreadable.
However, to me it looks like you are editing C source code, and in those cases I prefer to use parametric patches.
I'm sorry to say, but I think this brings in an impurity that may cause different build results with the same hash, if for some reason a package uses this environment variable to make decisions. |
That's indeed correct, it being an impurity is the whole point. Same drv, different log output. If your derivation used |
Isn't this whole structured logging functionality in Nix the right candidate for this? Shouldn't this allow us to send these debug messages to there, and it'd be up to nix to filter this dynamically? |
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.
What if we use msg
action with level
for @nix
(i.e. #328229 (comment)) and then work on supporting multiple log levels for --print-build-logs
in Nix? E.g. implement some function nixLogWithLevel
that maps human-readable log level names to integers for @nix
and use that instead of nixLogDebug
.
This looks like a reasonable compromise to me because it appears to avoid log spam during builds (that I think was the main concern in #328229) but we’d retain these messages in nix log
.
$ cat msglevel.nix
let
pkgs = import ./. { };
in
pkgs.runCommand "nix-msg-level" { } ''
nixLog "@nix { \"action\": \"msg\", \"msg\": \"hello world\", \"level\": 7 }"
touch -- "$out"
''
$ nix build --rebuild --print-build-logs --file msglevel.nix
$ nix log ./result
@nix { "action": "msg", "msg": "hello world", "level": 7 }
(I’ve intentionally omitted sourcing setup hook
logs above for brevity)
Nix seems to filter out messages with level
≥ 4 by default.
Today, my plan is to split this into three PRs:
Related PRs and projects I've found from feedback on Matrix and elsewhere:
Please let me know if there are other links and projects of note. |
Closed because #331560 has landed. I'll commence work on this:
|
Motivation for changes
Sourcing setup hook *default hook*
spam in writers/trivial builders #328229Ever since Qyriad's excellent PRs (#290081, #310387) to make hooks more visible in the nixpkgs stdenv landed, we've been caught between two goals:
In the issue linked above, there's a real tension: we want to understand what's happening with a derivation without changing its hash -- but we also don't want to see this debugging information every time.
Description of changes
These commits piggyback on the existing
NIX_DEBUG
environment variable to turn on and turn off the hook logging. So, ifNIX_DEBUG
is1
or greater, the hook logging is turned on.There was, however, no documented way of setting the
NIX_DEBUG
variable in the Nix build environment.This patch adds an off-by-default option to the Nix and Lix derivations which allows building Nix such that the
NIX_DEBUG
variable is set in the Nix build environment.Yes, this is a total hack, and has no upstream warranty either express or implied. For such a "deep into the sauce" sort of debugging that needs this variable set, I feel that's OK.
I'll extract the somewhat arcane
grep | sed
thing into an actual patch if people are aligned on this direction.Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Fixes #328229.