maralorn / nix-output-monitor

Pipe your nix-build output through the nix-output-monitor a.k.a nom to get additional information while building.
GNU Affero General Public License v3.0
935 stars 28 forks source link

bug: nom should return a non 0 return code on nixos-rebuild failure #156

Closed codingCoffee closed 3 weeks ago

codingCoffee commented 1 month ago

For example when running

nixos-rebuild switch --flake <path-to-flake> --log-format internal-json -v 2>&1 | nom --json

the nixos-rebuild command fails, because it doesn't have sudo permission. However, the output of the entire command suceeds because of piping the output to nom.

I came across this issue while trying to find a workaround for https://github.com/maralorn/nix-output-monitor/issues/68

Also when there is any kind of build failure, nom returns a success response, which makes a little difficult to use in scripts. Maybe somehow piping the exit code of the command preceeding nom as nom's exit code might do the trick?

maralorn commented 3 weeks ago

I am not certain that nom should change it’s behavior.

When using nom in wrapper mode we do forward the exit code. But in pipe mode we don’t and I am not sure we can.

My recommendation would be to activate something like pipefail in the shell. I don’t see that nom should be erroring here, nom didn’t fail. And there are certainly possible failures of nixos-rebuild which nom couldn’t even detect.

As a workaround for #68 maybe try out: https://github.com/viperML/nh

codingCoffee commented 3 weeks ago

Ahh! I was missing the pipefail. My bad!