3   # Based on https://unix.stackexchange.com/questions/16578/resizable-serial-console-window
 
   4   resize = pkgs.writeScriptBin "resize" ''
 
   5     export PATH=${pkgs.coreutils}/bin
 
  11     if [[ "$TTY" != /dev/ttyS* ]] && [[ "$TTY" != /dev/ttyAMA* ]] && [[ "$TTY" != /dev/ttySIF* ]]; then
 
  12       # probably not a known serial console, we could make this check more
 
  13       # precise by using `setserial` but this would require some additional
 
  18     stty raw -echo min 0 time 5
 
  20     printf '\0337\033[r\033[999;999H\033[6n\0338' > /dev/tty
 
  21     IFS='[;R' read -r _ rows cols _ < /dev/tty
 
  24     stty cols "$cols" rows "$rows"
 
  28   # set terminal size once after login
 
  29   environment.loginShellInit = "${resize}/bin/resize";
 
  31   # allows user to change terminal size when it changed locally
 
  32   environment.systemPackages = [ resize ];
 
  34   # default is something like vt220... however we want to get alt least some colors...
 
  35   systemd.services."serial-getty@".environment.TERM = "xterm-256color";
 
  38     # also make grub respond on serial consoles
 
  39     boot.loader.grub.extraConfig = ''
 
  40     serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1
 
  41     terminal_input --append serial
 
  42     terminal_output --append serial