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" + ''; + }; +}