jetify-com / devbox

Instant, easy, and predictable development environments
https://www.jetify.com/devbox/
Apache License 2.0
7.83k stars 187 forks source link

internal/nix: log all command starts and exits #2135

Closed gcurtis closed 2 weeks ago

gcurtis commented 3 weeks ago

Write logs whenever a Nix command is about to start and after it exits. Make cmd a slog.LogValuer so that it writes structured log attributes grouped under a cmd prefix.

Example logs and attributes (line breaks added for readability):

msg="nix command starting"
    cmd.args="nix --extra-experimental-features ca-derivations --option experimental-features 'nix-command flakes fetch-closure' eval --impure --raw --expr builtins.currentSystem"
    cmd.path=/nix/var/nix/profiles/default/bin/nix

msg="nix command exited"
    cmd.args="nix --extra-experimental-features ca-derivations --option experimental-features 'nix-command flakes fetch-closure' eval --impure --raw --expr builtins.currentSystem"
    cmd.path=/nix/var/nix/profiles/default/bin/nix
    cmd.pid=68672
    cmd.code=0
    cmd.dur=34.296041ms

Command exits are always logged at the debug level, even if the command exits with a non-zero exit code. This is because some commands might be expected to fail (for example, when checking if a path exists in the store).