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
835 stars 24 forks source link

Fails to read nixos-rebuild output correct #116

Open TheArcaneBrony opened 11 months ago

TheArcaneBrony commented 11 months ago

Output is spammed with @nix {"action":"start"... and seems to miss a lot of steps. Screenshot from 2023-09-26 14-17-05

TheArcaneBrony commented 11 months ago

Update: seems to be related to unbuffer

maralorn commented 11 months ago

Can you please share the command you ran?

TheArcaneBrony commented 11 months ago
unbuffer nixos-rebuild switch --flake .#Rory-nginx -j`nproc` --upgrade-all --log-format internal-json -v |& nom --json
maralorn commented 11 months ago

I am surprised that this is working at all. But I agree it’s weird that it works for some lines and doesn‘t for others.

TheArcaneBrony commented 11 months ago

if this is marked as an enhancement, i wonder if we could get a nom os-rebuild subcommand or similar?

maralorn commented 11 months ago

The wish for a nom supported nixos-rebuild has been voiced before. And is definitely an open feature request. But I think it is more about changing nixos-rebuild than solving this in nom.

The enhancement request that I see in this issue would be "make the --json parser cleanly pass-through non json lines and correctly detect all json lines." I consider this an enhancement and not a bug because the --json parser was never supposed to be used on non-json input.

TheArcaneBrony commented 11 months ago

what i personally ended up doing was using nom build to build the system closure and then using nixos-rebuild afterwards to deploy it

nom build .#nixosConfigurations.${2}.config.system.build.toplevel && sudo nixos-rebuild switch --flake .#${HOSTNAME} || exit 1
mibmo commented 7 months ago

does anyone know if there are any downsides to @TheArcaneBrony's approach? seems pretty good to me, all things considered :)

maralorn commented 7 months ago

No, that’s basically what I do.

becknik commented 5 months ago

You might find the nh cli helper particularly useful when it comes to using nom in conjunction with nixos-rebuild.

kurnevsky commented 2 months ago

does anyone know if there are any downsides to @TheArcaneBrony's approach? seems pretty good to me, all things considered :)

Looks like with this approach nix can't use ssh builders/extra substituters.

maralorn commented 2 months ago

@kurnevsky That seems highly unlikely.

kurnevsky commented 2 months ago

Well, it can use them if nom is launched as root, but not as plain user. Found this relevant nh issue: https://github.com/viperML/nh/issues/70

(the command I'm running is nom build --keep-going --option extra-substituters 'ssh://pc.local' --builders 'ssh://pc.local x86_64-linux,aarch64-linux - 32' "/etc/nixos#nixosConfigurations.${HOST}.config.system.build.toplevel")

mibmo commented 2 months ago

does anyone know if there are any downsides to @TheArcaneBrony's approach? seems pretty good to me, all things considered :)

Looks like with this approach nix can't use ssh builders/extra substituters.

They work fine for me, maybe there's something more to it? have you confirmed they work with the base nix command? maybe it's an issue of trusted vs non-trusted substituters? have you tried declaring them directly in your nix config using the nix.buildMachines and nix.settings.{substituters,trusted-public-keys} options?

I'd assume that, if it works with root, it's due to your normal user not being a trusted user.

mibmo commented 2 months ago

also, just fyi: instead of eval'ing twice (once with nom; once with nixos-rebuild), there's the alternative of building to a known directory (I use /tmp/nixos-configuration) then running sudo $KNOWN_DIR/bin/switch-to-configuration switch. AFAICT, this is exactly what nixos-rebuild switch does.

My full build command is (with added comparison to running system and split across lines):

nom build ~/dev/dotnix#nixosConfigurations.$(hostname).config.system.build.toplevel --out-link /tmp/nixos-configuration && \
  nvd diff /run/current-system /tmp/nixos-configuration && \
  sudo /tmp/nixos-configuration/bin/switch-to-configuration switch
maralorn commented 2 months ago

Well, nixos-rebuild also sets the generation via nix-env.

kurnevsky commented 2 months ago

it's an issue of trusted vs non-trusted substituters

I use trusted-public-keys for my substituters.

have you tried declaring them directly in your nix config using the nix.buildMachines

I haven't, since I don't usually have stable address for them, so I prefer to specify them dynamically.

kurnevsky commented 2 months ago

Also nixos-rebuild executes switch-to-configuration using systemd-run to mitigate https://github.com/NixOS/nixpkgs/issues/39118