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

doc/manual: Add 'Debugging Nix' section #11637

Merged
merged 7 commits into from
Nov 1, 2024

Conversation

michaelvanstraten
Copy link
Contributor

This PR adds a new 'Debugging Nix' section to the Nix manual. It provides instructions on how to build Nix with debug symbols and how to debug the Nix binary using debuggers like lldb.

Motivation

Currently, it's hard to get started with launching a debuggable instance of Nix. Building Nix with debug symbols requires knowledge of internal environment variables like mesonBuildType, which are not well-documented.

Context

Please see #11502.

Priorities and Process

Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

To debug the Nix binary you just built:

```console
[nix-shell]$ lldb -- ./subprojects/nix/nix
Copy link
Member

Choose a reason for hiding this comment

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

FWIW, I use gdb, and if you're in a nix develop shell, you can just do

gdb --args nix ...

i.e. no need to give a full path to the nix binary.

Copy link
Member

Choose a reason for hiding this comment

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

So meson actually installs it to /home/joerg/git/nix/out/bin which is not in PATH. But in that case we would also need to run ninjaInstallPhase. I think it makes sense that both build system choose different locations for our own sanity while we still have two and not put both in PATH. I actually prefer being explicit about the executable location, because it's less error prone for users following the tutorial. Let's say one person has exited the devshell to get a debugger and no longer has the PATH from it set, in that case they might run the debugger against the global installed nix, which is not good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I can confirm @Mic92 comment.

@michaelvanstraten
Copy link
Contributor Author

michaelvanstraten commented Oct 6, 2024

I haven't figured out how to both debug the nix-daemon and nix when the debugging user is not the owner of /nix.

We could use the --store option to point to a local store but that would make debugging harder.

Is there a way to point nix to a different socket in terms of the daemon?

@Mic92
Copy link
Member

Mic92 commented Oct 6, 2024

I haven't figured out how to both debug the nix-daemon and nix when the debugging user is not the owner of /nix.

We could use the --store option to point to a local store but that would make debugging harder.

Is there a way to point nix to a different socket in terms of the daemon?

if you run as root than nix won't use the nix-daemon but will have similar privileges. This might be helpful for debugging. Otherwise, you would need to run two debugger sessions.
One that runs the nix-daemon as root and a second one with the actual command.
Debuggers are not very good at tracking multiple processes.

@michaelvanstraten
Copy link
Contributor Author

if you run as root than nix won't use the nix-daemon but will have similar privileges.

Then the problem becomes that you can't reproduce the IPC interactions between the two.

@Mic92
Copy link
Member

Mic92 commented Oct 6, 2024

Usually you won't to need a debugger on both processes at the same time. You can just have the debugger on one process and than maybe verbose logging or strace on the other instance.

@michaelvanstraten
Copy link
Contributor Author

Usually you won't to need a debugger on both processes at the same time. You can just have the debugger on one process and than maybe verbose logging or strace on the other instance.

I recently had the problem that the nix-daemon wasn't able to access an ssh key needed to access a remote builder. This was do to the fact that the key was password protected and the subprocess was not piped back to the nix client.

@tomberek tomberek added the idea approved The given proposal has been discussed and approved by the Nix team. An implementation is welcome. label Oct 9, 2024
@ConnorBaker
Copy link
Contributor

This PR has been very helpful as I've been working on #11767; I'd like to see it merged if that's at all possible.

@fricklerhandwerk fricklerhandwerk removed their request for review October 31, 2024 18:31
@fricklerhandwerk fricklerhandwerk removed their assignment Oct 31, 2024
@fricklerhandwerk
Copy link
Contributor

fricklerhandwerk commented Oct 31, 2024

I don't have the bandwidth to get into the semantics of the instructions, so no review on that aspect from me. Looks reasonable from a cursory glance though.

@michaelvanstraten Please use one line per sentence and resolve comments (shall the suggestions be applied?) and merge conflicts, then I'll hit the button.

michaelvanstraten and others added 6 commits November 1, 2024 18:28
This commit adds a new 'Debugging Nix' section to the Nix manual. It provides instructions on how to build Nix with debug symbols and how to debug the Nix binary using debuggers like `lldb`.

Fixes NixOS#11502
@michaelvanstraten
Copy link
Contributor Author

@fricklerhandwerk should all be resolved.

@fricklerhandwerk
Copy link
Contributor

@michaelvanstraten thanks a lot. I have a few fixups, could you please allow reviewers to push to your PR branch?

@michaelvanstraten
Copy link
Contributor Author

Screenshot 2024-11-01 at 19 42 38

@fricklerhandwerk looks like it is enabled.

@fricklerhandwerk
Copy link
Contributor

fricklerhandwerk commented Nov 1, 2024

Hm, I get

To github.com:michaelvanstraten/nix.git
 ! [remote rejected]     michaelvanstraten/master -> michaelvanstraten/master (permission denied)
error: failed to push some refs to 'github.com:michaelvanstraten/nix.git'

Ah, maybe you inherited branch protection on your fork, and so I can't push to master specifically?

@michaelvanstraten
Copy link
Contributor Author

Let me add you as a contributer.

@michaelvanstraten
Copy link
Contributor Author

@fricklerhandwerk added you as a contributed at the fork.

@fricklerhandwerk fricklerhandwerk enabled auto-merge (squash) November 1, 2024 18:56
@fricklerhandwerk
Copy link
Contributor

fricklerhandwerk commented Nov 1, 2024

Thanks everyone for your patience! @michaelvanstraten great addition to the documentation. Keep them coming. 🙂

@fricklerhandwerk fricklerhandwerk merged commit 55fe4ee into NixOS:master Nov 1, 2024
11 checks passed
Mic92 added a commit to Mic92/nix-1 that referenced this pull request Nov 6, 2024
* doc/manual: Add 'Debugging Nix' section

This commit adds a new 'Debugging Nix' section to the Nix manual. It provides instructions on how to build Nix with debug symbols and how to debug the Nix binary using debuggers like `lldb`.

Co-authored-by: Jörg Thalheim <[email protected]>
Co-authored-by: Valentin Gagarin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation idea approved The given proposal has been discussed and approved by the Nix team. An implementation is welcome.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants