]> Git — Sourcephile - julm/julm-nix.git/blob - nixos/profiles/serial.nix
tmux: use resize-pane -Z
[julm/julm-nix.git] / nixos / profiles / serial.nix
1 { pkgs, ... }:
2 let
3 # Based on https://unix.stackexchange.com/questions/16578/resizable-serial-console-window
4 resize = pkgs.writeScriptBin "resize" ''
5 export PATH=${pkgs.coreutils}/bin
6 if [ ! -t 0 ]; then
7 # not a interactive...
8 exit 0
9 fi
10 TTY="$(tty)"
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
14 # dependency
15 exit 0
16 fi
17 old=$(stty -g)
18 stty raw -echo min 0 time 5
19
20 printf '\0337\033[r\033[999;999H\033[6n\0338' > /dev/tty
21 IFS='[;R' read -r _ rows cols _ < /dev/tty
22
23 stty "$old"
24 stty cols "$cols" rows "$rows"
25 '';
26 in
27 {
28 # set terminal size once after login
29 environment.loginShellInit = "${resize}/bin/resize";
30
31 # allows user to change terminal size when it changed locally
32 environment.systemPackages = [ resize ];
33
34 # default is something like vt220... however we want to get alt least some colors...
35 systemd.services."serial-getty@".environment.TERM = "xterm-256color";
36
37 /*
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
43 '';
44 */
45 }