Log the chosen build user when building
Is your feature request related to a problem?
Right now, to the best of my knowledge, it's not possible to determine which nix build user a build is assigned to. It would help in some use cases to know this. The two that come to mind for me are:
- Debugging nix builds. Hypothetically, imagine if a nix build hangs for some reason (e.g. I'm adding some new very unstable feature to nix). It's useful metadata to know which build user the build was assigned to if I need to pkill processes on that build user.
- Any sort of nix-top "state of the nix world" analysis. I'm particularly interested in this since I'm trying to implement nix-btm (aka a nix-top clone).
Proposed solution
When building a drv, print which builder is being used. E.g. something like derivation '/nix/store/somehash-myderivationname.drv' assigned to builder 'nixbld2'
Alternative solutions
Additional context
Checklist
- [x] checked latest Nix manual (source)
- [x] checked open feature issues and pull requests for possible duplicates
Add :+1: to issues you find important.
Build user selection is logged under higher verbosity levels, so you might want to poke at those if you haven't? They're spammy, but here's a filtered example:
$ nix-build -A systemd -vvv |& grep -C4 nixbld
building of '/nix/store/rrv5kd7z6n3k2793gvv07g8ri8hdil62-lvm2-2.03.35.drv^dev' from .drv file: waitee 'building of '/nix/store/24ij52gia0vkar0w0nbjvgc26in3c1w4-coreutils-9.8.drv^out' from .drv file' done; 6 left
building of '/nix/store/24ij52gia0vkar0w0nbjvgc26in3c1w4-coreutils-9.8.drv^out' from .drv file: in final_awaiter
building of '/nix/store/c8m2jss6l5jw65nslypvnl5175amzdsw-elfutils-0.193.drv^dev' from .drv file: return_value(Co&&)
building of '/nix/store/c8m2jss6l5jw65nslypvnl5175amzdsw-elfutils-0.193.drv^dev' from .drv file: in final_awaiter
found build user '_nixbld1'
found build user '_nixbld10'
found build user '_nixbld11'
found build user '_nixbld12'
found build user '_nixbld13'
found build user '_nixbld14'
found build user '_nixbld15'
found build user '_nixbld16'
found build user '_nixbld17'
found build user '_nixbld18'
found build user '_nixbld19'
found build user '_nixbld2'
found build user '_nixbld20'
found build user '_nixbld21'
found build user '_nixbld22'
found build user '_nixbld23'
found build user '_nixbld24'
found build user '_nixbld25'
found build user '_nixbld26'
found build user '_nixbld27'
found build user '_nixbld28'
found build user '_nixbld29'
found build user '_nixbld3'
found build user '_nixbld30'
found build user '_nixbld31'
found build user '_nixbld32'
found build user '_nixbld4'
found build user '_nixbld5'
found build user '_nixbld6'
found build user '_nixbld7'
found build user '_nixbld8'
found build user '_nixbld9'
trying user '_nixbld1'
killing all processes running under uid '351'
executing builder '/nix/store/k8a78r7j84kh8vagydpb8zwaqnjch8fd-bash-5.3p3/bin/bash'
using builder args '-e /nix/store/l622p70vy8k5sh7y5wizi5f2mic6ynpg-source-stdenv.sh /nix/store/shkw4qm9qcw5sc5n1k5jznc83ny02r39-default-builder.sh'
sandbox setup: Generated sandbox profile:
If that's not sufficient (I suspect correlating them may not be feasible once several builds are running), maybe just knowing where is enough context to open a PR:
https://github.com/NixOS/nix/blob/423e732b221a50071c9f94bf0c88600fa204bd9a/src/libstore/unix/user-lock.cc#L90
Thank you for the response and pointers--I missed those log messages (didn't the verbosity set high enough)! +1 it seems a bit hairy if there's a couple builds going on to infer which drv build is assigned to which builder. Also, in my case of a nix task monitor, I'm hoping to avoid having the user remember to increase their verbosity at every nix invocation (https://github.com/NixOS/nix/issues/14304 I think a global setting could be a proper fix, but this seems easier to implement)
I've read through the code and it wasn't clear to me how I could modify SimpleUserLock::acquire to have the drv information planned to be built on that builder (am I missing something? I didn't see state in a place where I could just grab it to print with the selected builder). I ended up making a similar change in #14654 , but at a place where the access to the drv being built is available.