add tigervnc import
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
|
||||
{
|
||||
imports = [
|
||||
./tigervnc.nix
|
||||
./hardware/hardware-configuration.nix
|
||||
];
|
||||
|
||||
@@ -50,8 +51,13 @@
|
||||
displayManager.gdm.enable = false;
|
||||
displayManager.sddm.enable = true;
|
||||
displayManager.sddm.wayland.enable = true;
|
||||
displayManager.autoLogin = {
|
||||
enable = false;
|
||||
user = "andreas";
|
||||
};
|
||||
|
||||
displayManager.cosmic-greeter.enable = false;
|
||||
displayManager.defaultSession = "gnome";
|
||||
displayManager.defaultSession = "cinnamon";
|
||||
|
||||
xserver = {
|
||||
enable = true; # Enable the deprecated X11 teletype terminal connection system.
|
||||
@@ -255,6 +261,22 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
services.xrdp = {
|
||||
enable = true;
|
||||
openFirewall = true;
|
||||
defaultWindowManager = "cinnamon-session";
|
||||
};
|
||||
|
||||
### tigervnc
|
||||
services.tigervnc = {
|
||||
enable = true;
|
||||
users = {
|
||||
andreas = {
|
||||
localhost = false; # true for SSH-only
|
||||
};
|
||||
};
|
||||
};
|
||||
### tigervnc END
|
||||
|
||||
# This value determines the NixOS release from which the default
|
||||
# settings for stateful data, like file locations and database versions
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
{ config, pkgs, lib, ... }:
|
||||
|
||||
let
|
||||
cfg = config.services.tigervnc;
|
||||
in
|
||||
{
|
||||
options.services.tigervnc = {
|
||||
enable = lib.mkEnableOption "TigerVNC x0vncserver (mirrors :0)";
|
||||
users = lib.mkOption {
|
||||
type = lib.types.attrsOf (lib.types.submodule ({ name, config, ... }: {
|
||||
options = {
|
||||
enableSharing = lib.mkOption { type = lib.types.bool; default = true; };
|
||||
port = lib.mkOption { type = lib.types.int; default = 5901; };
|
||||
localhost = lib.mkOption { type = lib.types.bool; default = false; };
|
||||
#geometry = lib.mkOption { type = lib.types.str; default = ""; };
|
||||
};
|
||||
}));
|
||||
default = { };
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
environment.systemPackages = [ pkgs.tigervnc pkgs.xhost pkgs.xauth ];
|
||||
|
||||
systemd.user.services = lib.mapAttrs' (user: opts:
|
||||
let svcName = "tigervnc-x0vncserver-${user}";
|
||||
in {
|
||||
name = svcName;
|
||||
value = lib.mkIf opts.enableSharing {
|
||||
description = "TigerVNC x0vncserver sharing :0 for ${user}";
|
||||
after = [ "graphical-session.target" ];
|
||||
partOf = [ "graphical-session.target" ];
|
||||
wantedBy = [ "graphical-session.target" ];
|
||||
|
||||
path = [ pkgs.tigervnc pkgs.xhost pkgs.xauth pkgs.coreutils ];
|
||||
|
||||
script = let
|
||||
# Build args array to avoid shell escaping hell
|
||||
vncArgs = [
|
||||
"-display :0"
|
||||
"-rfbport ${toString opts.port}"
|
||||
"-rfbauth $HOME/.vnc/passwd"
|
||||
"-AcceptSetDesktopSize=0"
|
||||
"-AlwaysShared"
|
||||
] #++ lib.optionals (opts.geometry != "") [ "-Geometry ${opts.geometry}" ]
|
||||
++ lib.optionals opts.localhost [ "-localhost" ];
|
||||
in ''
|
||||
set -euxo pipefail
|
||||
|
||||
# Password check
|
||||
mkdir -p "$HOME/.vnc"
|
||||
if [ ! -r "$HOME/.vnc/passwd" ]; then
|
||||
echo "ERROR: Run: vncpasswd ~/.vnc/passwd" >&2
|
||||
### CHANGE THE > in the above line TO A GREATER THAN SIGN! ###
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# X authority
|
||||
xhost +local:
|
||||
|
||||
# Clean x0vncserver args
|
||||
${pkgs.tigervnc}/bin/x0vncserver ${lib.concatStringsSep " " (map (arg: "${arg}") vncArgs)}
|
||||
'';
|
||||
|
||||
preStop = ''
|
||||
xhost -local:
|
||||
pkill -f "x0vncserver.*${toString opts.port}"
|
||||
'';
|
||||
|
||||
serviceConfig = {
|
||||
Type = "simple";
|
||||
Restart = "always";
|
||||
RestartSec = "5s";
|
||||
RuntimeDirectory = "vnc-${user}";
|
||||
};
|
||||
};
|
||||
}
|
||||
) cfg.users;
|
||||
|
||||
networking.firewall.allowedTCPPorts =
|
||||
lib.mapAttrsToList (_: opts: opts.port) cfg.users;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user