NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.88k stars 13.94k forks source link

TigerVNC: .vncserver-wrapped: couldn't find "xinit" on your PATH. #109500

Open tex opened 3 years ago

tex commented 3 years ago

tigervnc does not start due to ".vncserver-wrapped: couldn't find "xinit" on your PATH."

I have this in my NixOS configuration.nix:

   systemd.services."tigervnc-server" =                                                                                            
   { description = "TigerVNC Server";                                                                                              

     wantedBy = [ "multi-user.target" ];                                                                                           

     serviceConfig =                                                                                                               
     { StandardError = "journal";                                                                                                  
       ExecStart = ''                                                                                                              
         ${pkgs.bash}/bin/bash -c 'source ${config.system.build.setEnvironment} ; \                                                
                   exec $SHELL --login -c "exec ${pkgs.tigervnc}/bin/vncserver :5"'                                                
       '';                                                                                                                         
       Type = "forking";                                                                                                           
       User = "milan";                                                                                                             
       Restart = "always";                                                                                                         
       RestartSec = "10s";                                                                                                         
     };                                                                                                                            
   };                                                                                                                              

I have xorg enabled:

# Enable the X11 windowing system.
  services.xserver.enable = true;
  services.xserver.layout = "us";
  services.xserver.windowManager.i3.enable = true;

It is server without monitor connected.

Worked good until last update. I am on channel: nixos https://nixos.org/channels/nixos-20.09

It doesn't start even from command line if I install it with nix-shell -p tigervnc

tex commented 3 years ago

Probably connected with upgrade to 1.11.0 (https://github.com/NixOS/nixpkgs/commit/2829500ac2bdeb1e09ee9e169a0e72c357c052e5)

From Arch forum: You probably have an old /etc/pam.d/tigervnc, you need to delete that and rename the newest tigervnc.pacnew to tigervnc, otherwise vncsession-start fails ("Failure daemonizing"/"pam_open_session failed: 28 (Module is unknown)")

I tried to run vncsession and for this failure deamonizing error. There is no /etc/pam.d/tigervnc in my system.

tex commented 3 years ago

Also from Arch forum (https://bbs.archlinux.org/viewtopic.php?pid=1925998#p1925998)

tex commented 3 years ago

Anyone have a service already created for this?

iblech commented 3 years ago

In pkgs/tools/admin/tigervnc/default.nix, we list a couple of required packages in the PATH. At the time of writing, these are xterm twm xsetroot xauth. The error you pointed out is quickly fixed by adding xinit to this list.

However. It appears that the current version of tigervnc expects an Xsession file in /etc/X11. Hence tigervnc won't work even with this fix. Our tests would have caught this problem -- but unfortunately, I never got around to work on them again, the tests only exist as a pull request (#85214).

I might look into this later, but won't promise anything.

stale[bot] commented 3 years ago

I marked this as stale due to inactivity. → More info

typetetris commented 3 years ago

It is only a poor workaround, but you can use

xinit /home/user/.vnc/xstartup -- $(realpath $(which Xvnc)) :1 PasswordFile=/home/user/.vnc/passwd

to get a vncserver running similarly as before.

eljojo commented 2 years ago

@typetetris could you explain how to use that? would it be used in ExecStart for the service proposed above?

typetetris commented 2 years ago

You probably could make it work.

I never bothered. I start the vncserver when I need it, from the command line. An always running vncserver makes me uncomfortable.

michaelCTS commented 11 months ago

As a workaround, you should be able to add the xorg.xinit package to the list of packages required in PATH of the systemd service using systemd.services.<name>.path (source).

The proper fix would probably be adding xorg.xinit to the list of dependencies for tigervnc

iblech commented 11 months ago

@michaelCTS Unfortunately I'm afraid I think this will not work, as I alluded to here.

Personally, I have no use for the modern Xsession infrastructure and just use the following simple custom replacement script for booting up a VNC session:

#!/usr/bin/env bash

# prepare Xauthority file
cookie=$(mcookie)
xauth -f $HOME/.Xauthority source - <<EOF
add $HOSTNAME:1 . $cookie 
add $HOSTNAME/unix:1 . $cookie
EOF

# logic lifted from sx 
trap 'DISPLAY=:1 exec xterm & wait "$!"' USR1
(trap "" USR1 && exec Xvnc :1 -auth $HOME/.Xauthority -desktop $HOSTNAME:1) & pid=$!
wait "$pid"

Perhaps we should include a version of this in our package?

st0fm commented 5 months ago

I just created a systemd service based on the workaround of @typetetris.

{ pkgs, ... }:
let
  home = "/home/user";
in
{
  environment.systemPackages = [pkgs.xorg.xinit];

  systemd.services.vncserver = {
    enable = true;
    environment = {
      PATH = pkgs.lib.mkForce "/run/wrappers/bin:${home}/.nix-profile/bin:/nix/profile/bin:${home}/.local/state/nix/profile/bin:/etc/profiles/per-user/user/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin";
    };
    unitConfig = {
      Description = "Remote desktop service (VNC)";
      After = "syslog.target network.target";
    };

    serviceConfig = {
      Type = "simple";
      User = "user";
      WorkingDirectory = "${home}";

      ExecStartPre = "/bin/sh -c '${pkgs.tigervnc}/bin/vncserver -kill :1 > /dev/null 2>&1 || :'";
      ExecStart = "${pkgs.xorg.xinit}/bin/xinit ${home}/.vnc/xstartup -- ${pkgs.tigervnc}/bin/Xvnc :1 -interface 127.0.0.1 -rfbauth ${home}/.vnc/passwd";
      ExecStop = "${pkgs.tigervnc}/bin/vncserver -kill :1";

    };

    wantedBy = ["multi-user.target"];

  };
}

xstartup

#!/bin/sh

exec $(realpath $(which i3))

Just hard-coded the PATH variable to get it working, not sure if there is a better way.