Mic92 / nixos-shell

Spawns lightweight nixos vms in a shell
MIT License
685 stars 39 forks source link

shell config: only resize if on tty #84

Closed tropf closed 1 month ago

tropf commented 1 month ago

Dear Mic92 (and other maintainers?),

when trying to spawn a VM for testing through nixos-shell, I encountered errors when invoking command through ssh host COMMAND. This always showed the message resize: can't open terminal /dev/tty before the command output (which still ran successfully itself).

This is caused by an entry in /etc/profile, configured in share/modules/nixos-shell-config.nix, which calls resize indiscriminately. This PR adds a condition to the resize invocation to only call in TTYs.

To quote the commit message:

Resize is only called if stdout is opened. This is checked through the test command. As it is not a shell builtin in all POSIX shells (although it is it is in bash), it is called from the coreutils packages using its full path. (The alternative of adding coreutils to the globally installed system packages might break setups.)

The previous configuration calls resize on any login shell through /etc/profile, which outputs an error messages on shells not on a tty. (That can occur when using ssh to call a command directly, i.e. ssh host echo foo).