From afdb3ee5fe6e6ce2447f4838ca88108525b0ee4b Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 13 Nov 2026 14:01:28 +0000 Subject: krops: add allocateTTY to writeDeploy With allocateTTY, nixos-rebuild runs with a terminal, so it shows colours and progress: on remote targets, ssh gets -t, which allocates a terminal if its own input is one, and on the local target, expect's unbuffer provides one. The nixos-rebuild stand-in records whether its output is a terminal. --- tests/nixos-rebuild.sh | 6 ++++-- tests/scenarios.nix | 23 ++++++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/nixos-rebuild.sh b/tests/nixos-rebuild.sh index 9e2e47e..ec0c85c 100755 --- a/tests/nixos-rebuild.sh +++ b/tests/nixos-rebuild.sh @@ -1,8 +1,10 @@ #! /bin/sh -# Stands in for nixos-rebuild: records the user it runs as, NIX_PATH, and its -# arguments in /tmp/nixos-rebuild.log. +# Stands in for nixos-rebuild: records the user it runs as, NIX_PATH, its +# arguments, and whether its output is a terminal in /tmp/nixos-rebuild.log. +if test -t 1; then terminal=terminal; else terminal='no terminal'; fi { id -u printf '%s\n' "${NIX_PATH-}" printf '%s\n' "$*" + echo "$terminal" } > /tmp/nixos-rebuild.log diff --git a/tests/scenarios.nix b/tests/scenarios.nix index e618fcd..2fc1bd7 100644 --- a/tests/scenarios.nix +++ b/tests/scenarios.nix @@ -786,7 +786,28 @@ assert !(krops.isLocalTarget (targets.remote "/")); expect_eq arguments "$(sed -n 3p /tmp/nixos-rebuild.log)" "$expected" ''; }; - }); + }) + + # writeDeploy with allocateTTY: nixos-rebuild's output is a terminal on + # the local target. ssh allocates one on remote targets only if its own + # input is a terminal, which the tests' isn't. + ++ map (targetKind: scenario { + name = "deploy-${targetKind}-allocateTTY"; + inherit targetKind; + prepare = '' + rm -f /tmp/nixos-rebuild.log /etc/nixos/flake.nix + ''; + phases = [{ + sources.x.file = "/fixtures/alt"; + deploy.allocateTTY = true; + check = '' + expect_eq arguments "$(sed -n 3p /tmp/nixos-rebuild.log)" switch + expect_eq terminal "$(sed -n 4p /tmp/nixos-rebuild.log)" ${ + if targetKind == "local" then "terminal" else "'no terminal'" + } + ''; + }]; + }) targetKinds; # Features spanning several sources. features = concatMap (targetKind: let -- cgit v1.3.1