nixos/stage-2: Added boot.logCommands

authored by Roger Qiu and committed by Eelco Dolstra 474d5a7b 142f65e0

+33 -1
+24
nixos/modules/system/boot/stage-2-init.sh
··· 155 mount -t tmpfs -o "mode=0755" tmpfs /var/setuid-wrappers 156 157 158 # Run the script that performs all configuration activation that does 159 # not have to be done at boot time. 160 echo "running activation script..." ··· 180 181 # Run any user-specified commands. 182 @shell@ @postBootCommands@ 183 184 185 # Start systemd.
··· 155 mount -t tmpfs -o "mode=0755" tmpfs /var/setuid-wrappers 156 157 158 + # Optionally log the script output to /dev/kmsg or /run/log/stage-2-init.log. 159 + # Only at this point are all the necessary prerequisites ready for these commands. 160 + if test -n "@logCommands@"; then 161 + exec {logOutFd}>&1 {logErrFd}>&2 162 + if test -w /dev/kmsg; then 163 + exec > >(tee -i /proc/self/fd/"$logOutFd" | while read line; do 164 + if test -n "$line"; then 165 + echo "stage-2-init: $line" > /dev/kmsg 166 + fi 167 + done) 2>&1 168 + else 169 + mkdir -p /run/log 170 + exec > >(tee -i /run/log/stage-2-init.log) 2>&1 171 + fi 172 + fi 173 + 174 + 175 # Run the script that performs all configuration activation that does 176 # not have to be done at boot time. 177 echo "running activation script..." ··· 197 198 # Run any user-specified commands. 199 @shell@ @postBootCommands@ 200 + 201 + 202 + # Reset the logging file descriptors 203 + if test -n "@logCommands@"; then 204 + exec 1>&$logOutFd 2>&$logErrFd 205 + exec {logOutFd}>&- {logErrFd}>&- 206 + fi 207 208 209 # Start systemd.
+9 -1
nixos/modules/system/boot/stage-2.nix
··· 17 src = ./stage-2-init.sh; 18 shellDebug = "${pkgs.bashInteractive}/bin/bash"; 19 isExecutable = true; 20 - inherit (config.boot) devShmSize runSize; 21 inherit (config.nix) readOnlyStore; 22 inherit (config.networking) useHostResolvConf; 23 ttyGid = config.ids.gids.tty; ··· 39 options = { 40 41 boot = { 42 43 postBootCommands = mkOption { 44 default = "";
··· 17 src = ./stage-2-init.sh; 18 shellDebug = "${pkgs.bashInteractive}/bin/bash"; 19 isExecutable = true; 20 + inherit (config.boot) logCommands devShmSize runSize; 21 inherit (config.nix) readOnlyStore; 22 inherit (config.networking) useHostResolvConf; 23 ttyGid = config.ids.gids.tty; ··· 39 options = { 40 41 boot = { 42 + 43 + logCommands = mkOption { 44 + default = false; 45 + type = types.bool; 46 + description = '' 47 + Whether to replicate command output of stage-1 booting to <filename>/dev/kmsg</filename> or <filename>/run/log/stage-2-init.log</filename> if <filename>/dev/kmsg</filename> is not writable. 48 + ''; 49 + }; 50 51 postBootCommands = mkOption { 52 default = "";