Open davidak opened 4 years ago
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/how-to-setup-vnc-server-on-nixos/7603/4
I marked this as stale due to inactivity. → More info
still needed
I marked this as stale due to inactivity. → More info
still needed
I found a solution (taken from this example https://git.thalheim.io/Mic92/stockholm/src/branch/master/makefu/2configs/vncserver.nix and https://github.com/hyphon81/Nixtack/blob/master/noVNC/noVNC.nix)
configuration.nix
file:
{ config, pkgs, lib, ... }:
with lib;
let
pwfile = "/home/user/.vnc/passwd"; # vncpasswd
pwtmp = "/tmp/vnc-password";
user = "user";
vnc_port = 5900;
web_port = 6080;
novnc = pkgs.callPackage /home/user/.mynix/novnc/default.nix {};
in
{
....
systemd.services = {
# TODO: terminal-server without a real gui and virtual display manager
terminal-server = {
description = "VNC Terminal Server";
after = [ "display-manager.service" "graphical.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
User = user;
Restart = "always";
ExecStartPre = pkgs.writers.writeDash "terminal-pre" ''
sleep 5
install -m0700 -o ${user} ${pwfile} ${pwtmp}
'';
ExecStart = "${pkgs.tigervnc}/bin/x0vncserver -display :0 -rfbport ${toString vnc_port} -passwordfile ${pwfile}";
PermissionsStartOnly = true;
PrivateTmp = true;
};
};
terminal-web = {
description = "noVNC Web Server";
after = [ "terminal-server.service" "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
User = "nobody";
ExecStart = "${novnc}/bin/launch-novnc.sh --listen ${toString web_port} --vnc localhost:${toString vnc_port}";
PrivateTmp = true;
};
};
};
# Nginx for VNC
services.nginx.enable = true;
services.nginx.virtualHosts._.locations = {
"/" = {
root = "${novnc}";
index = "vnc_auto.html";
};
"/websockify" = {
proxyPass = "http://127.0.0.1:6080/";
extraConfig = ''
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# VNC connection timeout
proxy_read_timeout 61s;
# Disable cache
proxy_buffering off;
'';
};
};
...
}
.mynix/novnc/default.nix
file:
{ stdenv, lib, fetchurl, pkgs }:
# source: https://github.com/hyphon81/Nixtack/blob/master/noVNC/noVNC.nix
let
in
stdenv.mkDerivation rec {
name = "novnc-${version}";
#version = "1.3.0";
version = "0.6.2";
src = fetchurl {
url = "https://github.com/novnc/noVNC/archive/v${version}.tar.gz";
#sha256 = "0dh3564xfsg5cy93fc36magpvs3y2sbmybqk9l2z9scw9i8r33zf";
sha256 = "16ygbdzdmnfg9a26d9il4a6fr16qmq0ix9imfbpzl0drfbj7z8kh";
};
p = lib.makeBinPath [ pkgs.nettools pkgs.python3Packages.websockify
pkgs.coreutils pkgs.which pkgs.procps ];
patchPhase = ''
sed -i '1aset -efu\nexport PATH=${p}\n' utils/launch.sh
'';
installPhase = ''
mkdir -p $out/bin
cp utils/launch.sh $out/bin/launch-novnc.sh
chmod +x $out/bin/launch-novnc.sh
mkdir -p $out/images
cp -r images/* $out/images/
mkdir -p $out/include
cp -r include/* $out/include/
cp favicon.ico $out
cp vnc.html $out
cp vnc_auto.html $out
'';
meta = with lib; {
homepage = http://novnc.com/info.html;
repositories.git = git://github.com/novnc/noVNC.git;
description = ''
A HTML5 VNC Client
'';
license = licenses.mpl20;
};
}
If you do not need a web client, you can only use terminal-server
. I hope it will help you.
There is the following, that is already declaratively configured with yaml, so we could easily implement it https://github.com/kasmtech/KasmVNC
Issue description
I would like to connect to a headless NixOS system via VNC.
I looked many times for "vnc" in NixOS options, but found nothing.
Now i found out, that there is a x11vnc package, but again no option.
So i searched nixpkgs for "x11vnc" and found: terminal-server.nix
It looks like what i want, but has no option to enable and is not documented anywhere.
Please provide a proper vnc-server option!
cc who edited terminal-server: @domenkozar @edolstra