Globally disable stripping of debug symbols

How would I go about preventing the stripping of debug symbols for all packages? It looks like gets bundled into stdenv. I guess checking out nixpkgs and just commenting that out would work in principle? I wonder if there’s a clever way to set it as override.

I tried a few ways of changing the defaultNativeBuildInputs of stdenv but tended to get infinite recursion or other weird errors.

You can do this with an overlay, like this:

self: super:
  stdenv = super.keepDebugInfo super.stdenv;

Build it like:

$ nix build --arg overlays '[ (self: super: { stdenv = super.keepDebugInfo super.stdenv; } )]' nixpkgs.hello

Unfortunately this is a mass rebuild, because everything in the stdenv needs to be rebuilt with debug symbols as well. You can also use “crossOverlays” to just get debug symbols for the last stage:

$ nix build --arg crossOverlays '[ (self: super: { stdenv = super.keepDebugInfo super.stdenv; } )]' nixpkgs.hello
$ file result/bin/hello
result/bin/hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /nix/store/avr2x43njlq4kyb1a9zgrh6fih5fq4si-glibc-2.27/lib/, for GNU/Linux 2.6.32, with debug_info, not stripped

Many thanks! I will leave that churning for a few days :slight_smile:

Impressively, not stripping causes a build to fail with a (spurious, I think) uninitialised variable error:

In file included from regex.c:67:0:
regexec.c: In function 'check_node_accept_bytes':
regexec.c:3802:29: error: 'extra' may be used uninitialized in this function [-Werror=maybe-uninitialized]
        const unsigned char *coll_sym = extra + cset->coll_syms[i];

Looking at the code it seems fine (extra must be set or the loop would not have been entered).

It’s strange that disabling the stripping made the compiler change its mind…

Try forcing a rebuild of this with debug symbol stripping? If you’re getting it as a substitute, maybe the build in general just fails on your machine for some reason. I think you can do this with nix-build '<nixpkgs>' -A hello --check

Slightly confused, or might not have explained myself. The above is in glibc, being built (as intended) without stripping. I got the above with

nix-build -E 'import <nixpkgs> {overlays = [(self: super: { stdenv = super.keepDebugInfo super.stdenv; } )];}' -A glibc

but I also get the same problem running @matthewbauer’s original command (should be the same derivation for glibc).

Cool, I didn’t know about that trick with keepDebugInfo, last time I ended up trying to hack enableDebugging into working with some language infrastructure. It was not a fun time and I gave up in the end (it used a custom builder for an interpreter who’s library build process was kind of weird though…).

I think it would be nice if we had some composeable, homogeneous conventions for enabling debug info on things.

I meant try to force a local build without using keepDebugInfo to see if the error you’re seeing really is coming from that, or is just a consequence of actually building it yourself (as opposed to getting it from a substitute).

@lilyball - sorry now I understand!

  • nix-build -E '(import <nixpkgs> {}).glibc' --check: works (but with non-deterministic)
    $ nix-build -E ‘with import {}; glibc’
  • nix-build -E 'with import <nixpkgs> {}; keepDebugInfo glibc' gives the same derivation as regular glibc!


$ nix-build -E 'with import <nixpkgs> {}; glibc'

That aside, I tried to move past the problem by disabling the compiler warning. I ended up with another strange problem. Here’s my default.nix:

with import <nixpkgs>
  overlays = [
    (self: super: {
      stdenv = super.keepDebugInfo super.stdenv;
      glibc = super.glibc.overrideAttrs (o: {
        preConfigure = o.preConfigure + ''
          export CFLAGS="-Wno-error=maybe-uninitialized $CFLAGS"

This fails with:

building '/nix/store/phdndsx0drab3jm06jyp8vgjpqs88zw1-stdenv-linux.drv'...
output '/nix/store/2dlzy6qmjhqgfpisxw85826lq5lw8lj2-stdenv-linux' is not allowed to refer to the following paths:
error: build of '/nix/store/phdndsx0drab3jm06jyp8vgjpqs88zw1-stdenv-linux.drv' failed

Added an issue stdenv cannot be built with keepDebugInfo · Issue #64980 · NixOS/nixpkgs · GitHub

Little bit of an update: the uninitialized error is because keepDebugInfo actually modifies some CFLAGS as well as setting dontStrip=true. If I instead use

      stdenv = super.stdenv // {
        mkDerivation = args: super.stdenv.mkDerivation (args // { dontStrip = true; });

then glibc compiles cleanly, but I still get the “is not allowed to” error above.