about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorGraham Christensen <graham@grahamc.com>2020-02-12 20:50:05 -0500
committerGraham Christensen <graham@grahamc.com>2020-02-12 21:18:27 -0500
commit2d42fc240c4035e6df5dbbef42a0e3693ede931d (patch)
tree50b63a4c41c93c1ffa86c3d1f1eaa80da8a9f690 /nixos
parent08444aa09b1caf7179ade0a7cc5592933e50dc45 (diff)
downloadnixlib-2d42fc240c4035e6df5dbbef42a0e3693ede931d.tar
nixlib-2d42fc240c4035e6df5dbbef42a0e3693ede931d.tar.gz
nixlib-2d42fc240c4035e6df5dbbef42a0e3693ede931d.tar.bz2
nixlib-2d42fc240c4035e6df5dbbef42a0e3693ede931d.tar.lz
nixlib-2d42fc240c4035e6df5dbbef42a0e3693ede931d.tar.xz
nixlib-2d42fc240c4035e6df5dbbef42a0e3693ede931d.tar.zst
nixlib-2d42fc240c4035e6df5dbbef42a0e3693ede931d.zip
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>
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/installer/tools/nixos-enter.sh18
1 files changed, 9 insertions, 9 deletions
diff --git a/nixos/modules/installer/tools/nixos-enter.sh b/nixos/modules/installer/tools/nixos-enter.sh
index 4680cd8ae95a..1fdd4627a902 100644
--- a/nixos/modules/installer/tools/nixos-enter.sh
+++ b/nixos/modules/installer/tools/nixos-enter.sh
@@ -60,15 +60,15 @@ chmod 0755 "$mountPoint/dev" "$mountPoint/sys"
 mount --rbind /dev "$mountPoint/dev"
 mount --rbind /sys "$mountPoint/sys"
 
-# If silent, write both stdout and stderr of activation script to /dev/null
-# otherwise, write both streams to stderr of this process
-if [ "$silent" -eq 0 ]; then
-    PIPE_TARGET="/dev/stderr"
-else
-    PIPE_TARGET="/dev/null"
-fi
+(
+    # If silent, write both stdout and stderr of activation script to /dev/null
+    # otherwise, write both streams to stderr of this process
+    if [ "$silent" -eq 1 ]; then
+        exec 2>/dev/null
+    fi
 
-# Run the activation script. Set $LOCALE_ARCHIVE to supress some Perl locale warnings.
-LOCALE_ARCHIVE="$system/sw/lib/locale/locale-archive" chroot "$mountPoint" "$system/activate" >>$PIPE_TARGET 2>&1 || true
+    # Run the activation script. Set $LOCALE_ARCHIVE to supress some Perl locale warnings.
+    LOCALE_ARCHIVE="$system/sw/lib/locale/locale-archive" chroot "$mountPoint" "$system/activate" 1>&2 || true
+)
 
 exec chroot "$mountPoint" "${command[@]}"