nix-output-monitor icon indicating copy to clipboard operation
nix-output-monitor copied to clipboard

Fails to read nixos-rebuild output correct

Open TheArcaneBrony opened this issue 1 year ago • 18 comments

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

TheArcaneBrony avatar Sep 26 '23 12:09 TheArcaneBrony

Update: seems to be related to unbuffer

TheArcaneBrony avatar Sep 26 '23 12:09 TheArcaneBrony

Can you please share the command you ran?

maralorn avatar Sep 26 '23 15:09 maralorn

unbuffer nixos-rebuild switch --flake .#Rory-nginx -j`nproc` --upgrade-all --log-format internal-json -v |& nom --json

TheArcaneBrony avatar Sep 29 '23 21:09 TheArcaneBrony

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.

maralorn avatar Sep 30 '23 08:09 maralorn

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

TheArcaneBrony avatar Oct 01 '23 20:10 TheArcaneBrony

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.

maralorn avatar Oct 02 '23 14:10 maralorn

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

TheArcaneBrony avatar Oct 10 '23 01:10 TheArcaneBrony

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

mibmo avatar Feb 03 '24 19:02 mibmo

No, that’s basically what I do.

maralorn avatar Feb 03 '24 20:02 maralorn

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

becknik avatar Apr 03 '24 15:04 becknik

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.

kurnevsky avatar Jul 14 '24 09:07 kurnevsky

@kurnevsky That seems highly unlikely.

maralorn avatar Jul 14 '24 09:07 maralorn

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")

kurnevsky avatar Jul 14 '24 09:07 kurnevsky

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 avatar Jul 14 '24 10:07 mibmo

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

mibmo avatar Jul 14 '24 10:07 mibmo

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

maralorn avatar Jul 14 '24 10:07 maralorn

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 avatar Jul 14 '24 11:07 kurnevsky

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

kurnevsky avatar Jul 14 '24 11:07 kurnevsky