Debug Symbols and Sources in shell.nix

I’m looking for something like the debuginfod that gdb supports. Essentially I want source+symbols for my project’s dependencies.

I’ve recently learned about enableDebugging (here) but it seems some packages are requiring an override, and I’m not entirely sure how to accomplish this. I’m probably abusing the design and doing something wrong. The project uses some utilities in llvm and I’d like to have the source+symbols from libLLVM available to gdb. I might extend the inputs list with additional dependencies that I might want debug symbols for.

with import <nixpkgs>{};
clangStdenv.mkDerivation {
  packages = [llvm.src];
  buildInputs = map enableDebugging [llvm];
  name = "clang nix shell";
  hardeningDisable = ["all"];
  shellHook = "fish";
}
error: attribute 'override' missing

       at /nix/store/dzys18by5mkr0ivs2q1bbjd8vbc182kz-nixos-22.11/nixos/pkgs/top-level/all-packages.nix:1082:26:

         1081|   # intended to be used like nix-build -E 'with import <nixpkgs> {}; enableDebugging fooPackage'
         1082|   enableDebugging = pkg: pkg.override { stdenv = stdenvAdapters.keepDebugInfo pkg.stdenv; };
             |                          ^
         1083|
(use '--show-trace' to show detailed location information)

Any help would be appreciated. I see here that NixOS might be planning to enable this at some point, but I might be mistaken.

Hi, I recently wrote a debuginfod server specifically for nix: GitHub - symphorien/nixseparatedebuginfod: Downloads and provides debug symbols and source code for nix derivations to gdb and other debuginfod-capable debuggers as needed. I was going to announce it when gdb with debuginfod support builds again on nixos-unstable. I think it provides what you want (debug symbols+source), provided that llvm is built with separateDebugInfo set to true. It looks like it is not the case.

overriding llvm does not look easy, you can avoid this need by cloning nixpkgs, modifying the source with nix edit -f. llvm directly and using import /path/to/clone instead of import <nixpkgs>.

Thanks for the info! I really do hope a common symbol server can be established, that with debuginfod would be amazing!

I’ve been able to solve my issue with the following shell.nix. It turns out I was calling a package that did not have an override; instead I should have been using llvmPackages.libllvm which does have an override defined:

with import <nixpkgs>{};
let
  llvmDbg = enableDebugging llvmPackages.libllvm;
in
  clangStdenv.mkDerivation {
    buildInputs = [llvmDbg];
    name = "clang nix shell";
    hardeningDisable = ["all"];
    shellHook = "fish";
  }