summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeon Schuermann <leon.git@is.currently.online>2019-08-13 23:05:22 +0200
committerLeon Schuermann <leon.git@is.currently.online>2019-08-13 23:48:58 +0200
commit415993d6b71b51742c7ecd1ace0ee42c9ae2a482 (patch)
treea43be52ddda8cd64cbbf9a5d506aecbfc416aa18
parent705b5cd05d1be32b83cfc097732214ce6cc35790 (diff)
downloadnixpkgs-415993d6b71b51742c7ecd1ace0ee42c9ae2a482.tar
nixpkgs-415993d6b71b51742c7ecd1ace0ee42c9ae2a482.tar.gz
nixpkgs-415993d6b71b51742c7ecd1ace0ee42c9ae2a482.tar.bz2
nixpkgs-415993d6b71b51742c7ecd1ace0ee42c9ae2a482.tar.lz
nixpkgs-415993d6b71b51742c7ecd1ace0ee42c9ae2a482.tar.xz
nixpkgs-415993d6b71b51742c7ecd1ace0ee42c9ae2a482.tar.zst
nixpkgs-415993d6b71b51742c7ecd1ace0ee42c9ae2a482.zip
nixos-enter: silent activation script option
Also, fix a few shellcheck errors.
-rw-r--r--nixos/doc/manual/man-nixos-enter.xml16
-rw-r--r--nixos/modules/installer/tools/nixos-enter.sh21
2 files changed, 33 insertions, 4 deletions
diff --git a/nixos/doc/manual/man-nixos-enter.xml b/nixos/doc/manual/man-nixos-enter.xml
index 42edaa1ae5b..1481db46712 100644
--- a/nixos/doc/manual/man-nixos-enter.xml
+++ b/nixos/doc/manual/man-nixos-enter.xml
@@ -34,6 +34,12 @@
     </arg>
      <replaceable>shell-command</replaceable>
    </arg>
+
+   <arg>
+    <arg choice='plain'>
+     <option>--silent</option>
+    </arg>
+   </arg>
     
    <arg>
     <arg choice='plain'>
@@ -102,6 +108,16 @@
    </varlistentry>
    <varlistentry>
     <term>
+     <option>--silent</option>
+    </term>
+    <listitem>
+     <para>
+       Suppresses all output from the activation script of the target system.
+     </para>
+    </listitem>
+   </varlistentry>
+   <varlistentry>
+    <term>
      <option>--</option>
     </term>
     <listitem>
diff --git a/nixos/modules/installer/tools/nixos-enter.sh b/nixos/modules/installer/tools/nixos-enter.sh
index 518dbbbf21e..4680cd8ae95 100644
--- a/nixos/modules/installer/tools/nixos-enter.sh
+++ b/nixos/modules/installer/tools/nixos-enter.sh
@@ -16,7 +16,8 @@ fi
 
 mountPoint=/mnt
 system=/nix/var/nix/profiles/system
-command=($system/sw/bin/bash "--login")
+command=("$system/sw/bin/bash" "--login")
+silent=0
 
 while [ "$#" -gt 0 ]; do
     i="$1"; shift 1
@@ -32,9 +33,12 @@ while [ "$#" -gt 0 ]; do
             exit 1
             ;;
         --command|-c)
-            command=($system/sw/bin/bash "-c" "$1")
+            command=("$system/sw/bin/bash" "-c" "$1")
             shift 1
             ;;
+        --silent)
+            silent=1
+            ;;
         --)
             command=("$@")
             break
@@ -51,11 +55,20 @@ if [[ ! -e $mountPoint/etc/NIXOS ]]; then
     exit 126
 fi
 
-mkdir -m 0755 -p "$mountPoint/dev" "$mountPoint/sys"
+mkdir -p "$mountPoint/dev" "$mountPoint/sys"
+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
+
 # 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" >&2 || true
+LOCALE_ARCHIVE="$system/sw/lib/locale/locale-archive" chroot "$mountPoint" "$system/activate" >>$PIPE_TARGET 2>&1 || true
 
 exec chroot "$mountPoint" "${command[@]}"