Skip to content
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

stdenv: Provide a way for full set -x debugging #29580

Merged
merged 4 commits into from Sep 26, 2017

Conversation

Ericson2314
Copy link
Member

@Ericson2314 Ericson2314 commented Sep 19, 2017

Motivation for this change

I need set -x all the time, and have been resorting to fairly ugly hacks to get it. @domenkozar needs it to. Re-purposing NIX_DEBUG as a "log-level"-style debugger seemed like a pretty non-intrusive way to achieve this.

Things done

I won't bother rebuilding the world just for this. But I'll be rebasing my #26805 on top of it.

  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • Linux
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

N.B. I often rebase my PRs on top of each other---they either depend or it's easier to chain rebase if the history is already linear-- -and this one landed on #29610. Just look the last 4 commits.

CC @orivej

@orivej
Copy link
Contributor

orivej commented Sep 20, 2017

If you want a less intrusive alternative, you could treat NIX_DEBUG as a string of one letter flags, using NIX_DEBUG=x and [[ "${NIX_DEBUG:-}" == *x* ]] to activate set -x. This will not require changing anything beyond stdenv/generic/setup.sh.


As a sidenote, I wrote a Linux tool that proved very useful to debug and inspect all kinds of build problems called fptrace. It supervises a build process and writes a shell script for each program launched during the build. You can examine what environment variables were set, what command line arguments were passed, and repeat any build step, possibly altering it beforehand. The command will look like fptrace -e -rm -s /tmp/fp nix-build -K ….

You may be aware of this, but @dezgeg wrote the great nix-debug-shell that surpassed my need for set -x in the stdenv.

@Ericson2314
Copy link
Member Author

@orivej I didn't know of either of those. Thanks, they look quite useful! There's still a need to debug the code before any the phases (say with all my changes to findInputs in #26805), though, and for this I think set -x is still useful. The two you mention are definitely better for debugging packages most of the time, however :).

@Ericson2314
Copy link
Member Author

We could use a set of flags, but seeing that this is a mass-rebuild no matter what, I don't mind changing all the use-sites: it makes things clearer for the reader.

@orivej
Copy link
Contributor

orivej commented Sep 20, 2017

You may also consider a more generic alternative: to evaluate an arbitrary value in setup.sh, e.g. eval "$NIX_DEBUG_STDENV_SETUP".

@domenkozar
Copy link
Member

I really like your improvements @Ericson2314 - just one request: can we update nixpkgs manual stdenv section to reflect such changes? In this case: https://nixos.org/nixpkgs/manual/#ssec-stdenv-attributes

@Ericson2314
Copy link
Member Author

@domenkozar Did that, and added wrapper script set -x at NIX_DEBUG >= 7.

@Ericson2314 Ericson2314 added this to Needed for binutils-wrapper in Cross compilation Sep 20, 2017
Copy link
Member

@domenkozar domenkozar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't actually built this, but it looks good. Having bash tracing helps many times.

@Ericson2314 Ericson2314 force-pushed the stdenv-super-debug branch 2 times, most recently from 362a42b to dbdec88 Compare September 21, 2017 01:27
Copy link
Member

@copumpkin copumpkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it

@Ericson2314 Ericson2314 force-pushed the stdenv-super-debug branch 5 times, most recently from 5135d0e to 0e67094 Compare September 22, 2017 00:14
@Ericson2314
Copy link
Member Author

[Did a little force-push and force-push dance to get github to pickup that the previous PR this was based off of is now merged. That will make the history easier to read for @edolstra, the only person whose opinion this is blocked on.]

Why 6? It seems a decently high number, giving us room for more degrees
of debugging before the `set -x` sledgehammer without incurring a
mass-rebuild.
@Ericson2314 Ericson2314 merged commit 87067dc into NixOS:staging Sep 26, 2017
@Ericson2314 Ericson2314 deleted the stdenv-super-debug branch September 26, 2017 18:05
@Ericson2314
Copy link
Member Author

@edolstra approved of this on IRC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Cross compilation
Needed for binutils-wrapper
Development

Successfully merging this pull request may close these issues.

None yet

5 participants