forked from clan/clan-core
add serial module to vms
This is useful for debugging in the cli.
This commit is contained in:
parent
48d7d5f38c
commit
64944f896a
32
nixosModules/clanCore/serial.nix
Normal file
32
nixosModules/clanCore/serial.nix
Normal file
@ -0,0 +1,32 @@
|
||||
{ pkgs, ... }:
|
||||
let
|
||||
# Based on https://unix.stackexchange.com/questions/16578/resizable-serial-console-window
|
||||
resize = pkgs.writeShellScriptBin "resize" ''
|
||||
export PATH=${pkgs.coreutils}/bin
|
||||
if [ ! -t 0 ]; then
|
||||
# not a interactive...
|
||||
exit 0
|
||||
fi
|
||||
TTY="$(tty)"
|
||||
if [[ "$TTY" != /dev/ttyS* ]] && [[ "$TTY" != /dev/ttyAMA* ]] && [[ "$TTY" != /dev/ttySIF* ]]; then
|
||||
# probably not a known serial console, we could make this check more
|
||||
# precise by using `setserial` but this would require some additional
|
||||
# dependency
|
||||
exit 0
|
||||
fi
|
||||
old=$(stty -g)
|
||||
stty raw -echo min 0 time 5
|
||||
|
||||
printf '\0337\033[r\033[999;999H\033[6n\0338' > /dev/tty
|
||||
IFS='[;R' read -r _ rows cols _ < /dev/tty
|
||||
|
||||
stty "$old"
|
||||
stty cols "$cols" rows "$rows"
|
||||
'';
|
||||
in
|
||||
{
|
||||
environment.loginShellInit = "${resize}/bin/resize";
|
||||
|
||||
# default is something like vt220... however we want to get alt least some colors...
|
||||
systemd.services."serial-getty@".environment.TERM = "xterm-256color";
|
||||
}
|
@ -3,6 +3,7 @@ let
|
||||
vmConfig = extendModules {
|
||||
modules = [
|
||||
(modulesPath + "/virtualisation/qemu-vm.nix")
|
||||
./serial.nix
|
||||
{
|
||||
virtualisation.fileSystems.${config.clanCore.secretsUploadDirectory} = lib.mkForce {
|
||||
device = "secrets";
|
||||
|
Loading…
Reference in New Issue
Block a user