home-manager: Prevent pipe failure when reading news

On my system (Fedora 43 with Nix 2.31.3) `home-manager news` exits
from `SIGPIPE` and never writes `~/.local/share/home-manager/news-read-ids`,
resulting in news items to never be marked read.  This is caused by
piping `(import ./news.nix).news.all` through `jq` and `less` failing
with an error as soon as `less` exits, which triggers `set -o pipefail`
to exit the shell running `home-manager` itself.

Avoiding the pipe into `$PAGER` avoids the problem.

Closes: https://github.com/nix-community/home-manager/issues/8690
References: https://github.com/jqlang/jq/issues/1017
References: https://www.greenend.org.uk/rjk/tech/shellmistakes.html#pipeerrors
This commit is contained in:
Dennis Schridde 2026-02-03 15:03:45 +01:00 committed by Austin Horstman
parent 984708c34d
commit 36349274d7

View file

@ -998,9 +998,11 @@ function doShowNews() {
return 1
esac
local formattedNewsFile="$WORK_DIR/news.txt"
nix-instantiate --quiet --eval --json --expr "(import ${newsNixFile}).news.$newsAttr" \
| jq -r . \
| ${PAGER:-less}
> "$formattedNewsFile"
${PAGER:-less} "$formattedNewsFile"
local allIds
allIds="$(nix-instantiate --quiet --eval --expr "(import ${newsNixFile}).meta.ids")"