git.iko.soy/typeable/nixpkgs
on master help sign in
nixos-enter: redirect to fd2 instead of a file named /dev/stderr

In some cases, /dev/stderr may not point to a sensible location. For example, running nixos-enter inside a systemd unit where the unit's StandardOutput and StandardError are set to be sockets. In these cases, this line would fail. Piping to fd2 directly works just as well, even under strange and twisted executions. Co-authored-by: Michael Bishop <michael.bishop@iohk.io>

commit2d42fc240c4035e6df5dbbef42a0e3693ede931d authorGraham Christensen <graham@grahamc.com> dateWed 12 Feb 2020, 20:50 (7 years ago) parent08444aa
1 file changed+9−9
nixos/modules/installer/tools/nixos-enter.sh+9−9
nixos/modules/installer/tools/nixos-enter.sh+9−9
@@ -60,15 +60,15 @@ chmod 0755 "$mountPoint/dev" "$mountPoint/sys"
6060mount --rbind /dev "$mountPoint/dev"
6161mount --rbind /sys "$mountPoint/sys"
6262
63−# If silent, write both stdout and stderr of activation script to /dev/null
64−# otherwise, write both streams to stderr of this process
65−if [ "$silent" -eq 0 ]; then
66− PIPE_TARGET="/dev/stderr"
67−else
68− PIPE_TARGET="/dev/null"
69−fi
63+(
64+ # If silent, write both stdout and stderr of activation script to /dev/null
65+ # otherwise, write both streams to stderr of this process
66+ if [ "$silent" -eq 1 ]; then
67+ exec 2>/dev/null
68+ fi
7069
71−# Run the activation script. Set $LOCALE_ARCHIVE to supress some Perl locale warnings.
72−LOCALE_ARCHIVE="$system/sw/lib/locale/locale-archive" chroot "$mountPoint" "$system/activate" >>$PIPE_TARGET 2>&1 || true
70+ # Run the activation script. Set $LOCALE_ARCHIVE to supress some Perl locale warnings.
71+ LOCALE_ARCHIVE="$system/sw/lib/locale/locale-archive" chroot "$mountPoint" "$system/activate" 1>&2 || true
72+)
7373
7474exec chroot "$mountPoint" "${command[@]}"