From bce1f0e91204889428cc10a10f15f5897f6bfdc0 Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Sat, 31 May 2025 19:32:56 +0200 Subject: [PATCH] shell.nix: wrap nixos-rebuild with nix-output-monitor \#nix-output-monitor-and-chill nom is only used if the output is a tty, and I provide a escape hatch in the form of NIX_NO_NOM=1. This solution sidesteps issues like `sudo nixos-rebuild ... |& nom` capturing the sudo password prompt. --- justfile | 2 +- shell.nix | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/justfile b/justfile index 31aa607..e21ec1f 100644 --- a/justfile +++ b/justfile @@ -26,7 +26,7 @@ run-vm machine=`just _a_machine` *_: | xargs -d'\n' nix flake update "$@" @repl $machine=`just _a_machine` *_: - set -v; nixos-rebuild --flake .#"$machine" repl "${@:2}" + set -v; NIX_NO_NOM=1 nixos-rebuild --flake .#"$machine" repl "${@:2}" @eval $machine=`just _a_machine` $attrpath="system.build.toplevel.outPath" *_: set -v; nix eval {{nix_eval_opts}} ".#nixosConfigurations.\"$machine\".config.$attrpath" --show-trace "${@:3}" diff --git a/shell.nix b/shell.nix index 8617b5f..2364d8d 100644 --- a/shell.nix +++ b/shell.nix @@ -1,6 +1,18 @@ { pkgs ? import {} }: + +let + nixos-rebuild-nom = pkgs.writeScriptBin "nixos-rebuild" '' + if [[ -t 1 && -z "''${NIX_NO_NOM-}" ]]; then + exec ${pkgs.lib.getExe pkgs.nixos-rebuild} -L "$@" |& ${pkgs.lib.getExe pkgs.nix-output-monitor} + else + exec ${pkgs.lib.getExe pkgs.nixos-rebuild} -L "$@" + fi + ''; +in + pkgs.mkShellNoCC { packages = with pkgs; [ + nixos-rebuild-nom just jq gum