From 0056a5aea1a7b68bdacb7b829c325a1d4a3c4259 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Fri, 21 Feb 2020 19:11:58 +0100 Subject: [PATCH] debug: add module This one is fairly similar to `environment.enableDebugInfo`[1] (hence the name). It ensures that the `debug`-output of packages defined in `home.packages` is installed if available and ensures that `gdb`/`elfutils` find those symbols by adding `~/.nix-profile/lib/debug` to the `NIX_DEBUG_INFO_DIRS`[2] variable. [1] https://github.com/NixOS/nixpkgs/blob/release-19.09/nixos/modules/config/debug-info.nix [2] https://github.com/NixOS/nixpkgs/blob/release-19.09/pkgs/development/tools/misc/gdb/debug-info-from-env.patch PR #1040 --- modules/misc/debug.nix | 26 ++++++++++++++++++++++++++ modules/modules.nix | 1 + tests/default.nix | 3 ++- tests/modules/misc/debug/default.nix | 25 +++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 modules/misc/debug.nix create mode 100644 tests/modules/misc/debug/default.nix diff --git a/modules/misc/debug.nix b/modules/misc/debug.nix new file mode 100644 index 000000000..d27d496b4 --- /dev/null +++ b/modules/misc/debug.nix @@ -0,0 +1,26 @@ +{ config, pkgs, lib, ... }: + +with lib; + +{ + options.home = { + enableDebugInfo = mkEnableOption "" // { + description = '' + Some Nix-packages provide debug symbols for + gdb in the debug-output. + This option ensures that those are automatically fetched from + the binary cache if available and gdb is + configured to find those symbols. + ''; + }; + }; + + config = mkIf config.home.enableDebugInfo { + home.extraOutputsToInstall = [ "debug" ]; + + home.sessionVariables = { + NIX_DEBUG_INFO_DIRS = + "$NIX_DEBUG_INFO_DIRS\${NIX_DEBUG_INFO_DIRS:+:}${config.home.profileDirectory}/lib/debug"; + }; + }; +} diff --git a/modules/modules.nix b/modules/modules.nix index 263c1176c..83d5a4dd5 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -26,6 +26,7 @@ let (loadModule ./home-environment.nix { }) (loadModule ./manual.nix { }) (loadModule ./misc/dconf.nix { }) + (loadModule ./misc/debug.nix { }) (loadModule ./misc/fontconfig.nix { }) (loadModule ./misc/gtk.nix { }) (loadModule ./misc/lib.nix { }) diff --git a/tests/default.nix b/tests/default.nix index 11e9b7d2f..5a342625a 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -43,10 +43,11 @@ import nmt { ./modules/programs/zsh ./modules/xresources ] ++ lib.optionals pkgs.stdenv.hostPlatform.isLinux [ - ./modules/programs/abook + ./modules/misc/debug ./modules/misc/pam ./modules/misc/xdg ./modules/misc/xsession + ./modules/programs/abook ./modules/programs/firefox ./modules/programs/getmail ./modules/programs/rofi diff --git a/tests/modules/misc/debug/default.nix b/tests/modules/misc/debug/default.nix new file mode 100644 index 000000000..b42462d08 --- /dev/null +++ b/tests/modules/misc/debug/default.nix @@ -0,0 +1,25 @@ +{ + debug = { pkgs, config, lib, ... }: { + home.enableDebugInfo = true; + home.packages = with pkgs; [ curl gdb ]; + + nmt.script = '' + [ -L $TESTED/home-path/lib/debug/curl ] \ + || fail "Debug-symbols for pkgs.curl should exist in \`/home-path/lib/debug'!" + + #source $TESTED/home-path/etc/profile.d/hm-session-vars.sh + #[[ "$NIX_DEBUG_INFO_DIRS" =~ /lib/debug$ ]] \ + #|| fail "Invalid NIX_DEBUG_INFO_DIRS!" + assertFileExists home-path/etc/profile.d/hm-session-vars.sh + assertFileRegex home-path/etc/profile.d/hm-session-vars.sh \ + 'NIX_DEBUG_INFO_DIRS=.*/lib/debug' + + # We need to override NIX_DEBUG_INFO_DIRS here as $HOME evalutes to the home + # of the user who executes this testcase :/ + { echo quit | PATH="$TESTED/home-path/bin''${PATH:+:}$PATH" NIX_DEBUG_INFO_DIRS=$TESTED/home-path/lib/debug \ + gdb curl 2>&1 | \ + grep 'Reading symbols from ${builtins.storeDir}/'; \ + } || fail "Failed to read debug symbols from curl in gdb" + ''; + }; +}