Last active
November 15, 2024 17:20
-
-
Save alexhrescale/e5cfa32a6f48ca23a961be2088b0ff8c to your computer and use it in GitHub Desktop.
nix-vnc-setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# as of this gist, tigervnc fails to build on the latest nix channel. | |
# this gist demonstrates using older build to launch it, with openbox | |
nix-channel --add https://nixos.org/channels/nixos-18.09 | |
nix-channel --update | |
export DISPLAY=:1 | |
export NIX_PATH=nixpkgs=/nix/var/nix/profiles/per-user/$USER/channels/nixos-18.09 | |
# for changing the geometry online, see https://stackoverflow.com/a/38630417 | |
case $1 in | |
init) | |
mkdir -p $HOME/.vnc | |
touch $HOME/.vnc/passwd | |
chmod 0600 $HOME/.vnc/passwd | |
cat > $HOME/.vnc/xstartup <<'EOF' | |
#!/bin/sh | |
unset SESSION_MANAGER | |
unset DBUS_SESSION_BUS_ADDRESS | |
OS=`uname -s` | |
if [ $OS = 'Linux' ]; then | |
case "$WINDOWMANAGER" in | |
*gnome*) | |
if [ -e /etc/SuSE-release ]; then | |
PATH=$PATH:/opt/gnome/bin | |
export PATH | |
fi | |
;; | |
esac | |
fi | |
if [ -x /etc/X11/xinit/xinitrc ]; then | |
exec /etc/X11/xinit/xinitrc | |
fi | |
if [ -f /etc/X11/xinit/xinitrc ]; then | |
exec sh /etc/X11/xinit/xinitrc | |
fi | |
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources | |
xsetroot -solid grey | |
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" & | |
openbox & | |
EOF | |
chmod +x $HOME/.vnc/xstartup | |
nix-shell -p openbox tigervnc --run "echo asdfasdf | vncpasswd -f > $HOME/.vnc/passwd; touch $HOME/.vnc/config; vncserver -geometry 1200x1920 $DISPLAY" | |
;; | |
add-mode) | |
# ref https://github.com/ebertland/home-bin/blob/master/add-vnc-mode | |
# you may be able to simply run the xrandr command without adding the mode | |
GEOMETRY=$2 | |
DIMS=($(echo $GEOMETRY|tr 'x' ' ')) | |
W=${DIMS[0]} | |
H=${DIMS[0]} | |
FPS=$(echo "$W * $H * 60 / 1000000" | bc) | |
nix-shell -p xorg.xrandr --run " | |
xrandr --newmode $GEOMETRY $FPS $W 0 0 $W $H 0 0 $H | |
xrandr --addmode VNC-0 $GEOMETRY | |
echo 'DONE: run xrandr --fb $GEOMETRY' to change the resolution | |
" | |
exit | |
;; | |
*) | |
nix-shell -p openbox tigervnc | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
благослави тебя господь бог