WIP: VNC Module #62

Closed
b12f wants to merge 9 commits from feature/wayvnc into main
8 changed files with 190 additions and 29 deletions

View file

@ -0,0 +1,73 @@
{ lib, config, pkgs, ... }:
with lib;
let
psCfg = config.pub-solar;
cfg = config.pub-solar.headless-graphical;
in
{
options.pub-solar.headless-graphical = {
enable = mkEnableOption "Enable headless sway and VNC";
};
config = mkIf cfg.enable {
programs.sway.enable = true;
xdg.portal = {
enable = true;
extraPortals = with pkgs; [ xdg-desktop-portal-gtk xdg-desktop-portal-wlr ];
gtkUsePortal = true;
};
services.pipewire.enable = true;
home-manager = with pkgs; pkgs.lib.setAttrByPath [ "users" psCfg.user.name ] {
home.packages = with pkgs; [
sway
grim
kanshi
mako
slurp
swayidle
swaylock
swaybg
xwayland
libappindicator-gtk3
wl-clipboard
wf-recorder
brightnessctl
gammastep
geoclue2
xsettingsd
ydotool
swaylock-bg
sway-launcher
import-gtk-settings
s
wcwd
];
programs.waybar.enable = true;
systemd.user.services.mako = import ./mako.service.nix pkgs;
systemd.user.services.swayidle = import ./swayidle.service.nix pkgs;
systemd.user.services.xsettingsd = import ./xsettingsd.service.nix pkgs;
systemd.user.services.waybar = import ./waybar.service.nix pkgs;
systemd.user.targets.sway-session = import ./sway-session.target.nix pkgs;
systemd.user.services.sway-headless = mkIf cfg.vnc.enable (import ./wayvnc.service.nix pkgs);
systemd.user.services.wayvnc = mkIf cfg.vnc.enable (import ./wayvnc.service.nix pkgs);
xdg.configFile."sway/config".source = ./config/config;
xdg.configFile."sway/config.d/colorscheme.conf".source = ./config/config.d/colorscheme.conf;
xdg.configFile."sway/config.d/theme.conf".source = ./config/config.d/theme.conf;
xdg.configFile."sway/config.d/gaps.conf".source = ./config/config.d/gaps.conf;
xdg.configFile."sway/config.d/custom-keybindings.conf".source = ./config/config.d/custom-keybindings.conf;
xdg.configFile."sway/config.d/applications.conf".source = ./config/config.d/applications.conf;
xdg.configFile."sway/config.d/systemd.conf".source = ./config/config.d/systemd.conf;
xdg.configFile."wayvnc/config".text = import ./config/wayvnc/config.nix { inherit psCfg; inherit pkgs; };
};
};
}

View file

@ -1,18 +1,30 @@
pkgs: pkgs:
{ {
Unit = { Unit = {
Description = "sway - SirCmpwn's Wayland window manager"; Description = "Headless sway - SirCmpwn's Wayland window manager";
Documentation = [ "man:sway(5)" ]; Documentation = [ "man:sway(5)" ];
BindsTo = [ "graphical-session.target" ]; BindsTo = [ "graphical-session.target" ];
Wants = [ "graphical-session-pre.target" ]; Wants = [ "graphical-session-pre.target" ];
After = [ "graphical-session-pre.target" ]; After = [ "graphical-session-pre.target" ];
}; };
Service = { Service = {
Type = "simple"; Type = "simple";
ExecStart = "${pkgs.sway}/bin/sway";
ExecStart = "${pkgs.sway}/bin/sway --headless";
Environment = [
"WLR_BACKENDS=headless"
"WLR_RENDERER=pixman"
"WLR_LIBINPUT_NO_DEVICES=1"
];
Restart = "on-failure"; Restart = "on-failure";
RestartSec = "1"; RestartSec = "1";
TimeoutStopSec = "10"; TimeoutStopSec = "10";
ExecStopPost = "${pkgs.systemd}/bin/systemctl --user unset-environment SWAYSOCK DISPLAY I3SOCK WAYLAND_DISPLAY"; ExecStopPost = "${pkgs.systemd}/bin/systemctl --user unset-environment SWAYSOCK DISPLAY I3SOCK WAYLAND_DISPLAY";
}; };
Install = {
WantedBy = [ "sway-session.target" ];
};
} }

View file

@ -0,0 +1,20 @@
pkgs:
{
Unit = {
Description = "A VNC server for wlroots based Wayland compositors ";
Documentation = "https://github.com/any1/wayvnc";
BindsTo = [ "sway-session.target" ];
After = [ "graphical-session-pre.target" "network-online.target" ];
Wants = [ "graphical-session-pre.target" "network-online.target" ];
};
Service = {
Type = "simple";
Environment = "WAYLAND_DISPLAY=wayland-1";
ExecStart = "${pkgs.wayvnc}/bin/wayvnc --render-cursor --unix-socket /run/wayvnc.sock";
};
Install = {
WantedBy = [ "sway-session.target" ];
};
}

View file

@ -47,3 +47,11 @@ mode "$mode_system" {
bindsym Return mode "default" bindsym Return mode "default"
bindsym Escape mode "default" bindsym Escape mode "default"
} }
set $mode_vncclient In VNCClient mode. Press $mod+Num_Lock or $mod+Shift+Escape to return.
bindsym $mod+Num_Lock mode "$mode_vncclient"
bindsym $mod+Shift+Escape mode "$mode_vncclient"
mode "$mode_vncclient" {
bindsym $mod+Num_Lock mode "default"
bindsym $mod+Shift+Escape mode "default"
}

View file

@ -0,0 +1,8 @@
{ psCfg, pkgs }: "
address=0.0.0.0
enable_auth=true
username=${psCfg.user.name}
password=testtest
private_key_file=/run/agenix/vnc-key.pem
certificate_file=/run/agenix/vnc-cert.pem
"

View file

@ -3,21 +3,28 @@ with lib;
let let
psCfg = config.pub-solar; psCfg = config.pub-solar;
cfg = config.pub-solar.sway; cfg = config.pub-solar.sway;
headlessCfg = config.pub-solar.sway-headless;
in in
{ {
options.pub-solar.sway = { options.pub-solar.sway = {
enable = mkEnableOption "Life in boxes"; enable = mkEnableOption "Life in boxes";
};
options.pub-solar.sway.terminal = mkOption { terminal = mkOption {
type = types.nullOr types.str; type = types.nullOr types.str;
default = "alacritty"; default = "alacritty";
description = "Choose sway's default terminal"; description = "Choose sway's default terminal";
}; };
options.pub-solar.sway.v4l2loopback.enable = mkOption {
v4l2loopback.enable = mkOption {
type = types.bool; type = types.bool;
default = true; default = true;
description = "WebCam streaming tool"; description = "WebCam streaming tool";
}; };
};
options.pub-solar.sway-headless = {
enable = mkEnableOption "Enable headless sway and vnc service";
};
config = mkIf cfg.enable (mkMerge [ config = mkIf cfg.enable (mkMerge [
(mkIf (cfg.v4l2loopback.enable) { (mkIf (cfg.v4l2loopback.enable) {
@ -26,13 +33,12 @@ in
boot.extraModprobeConfig = '' boot.extraModprobeConfig = ''
options v4l2loopback exclusive_caps=1 devices=3 options v4l2loopback exclusive_caps=1 devices=3
''; '';
})
({
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [
linuxPackages.v4l2loopback linuxPackages.v4l2loopback
]; ];
})
({
programs.sway.enable = true; programs.sway.enable = true;
xdg.portal = { xdg.portal = {
@ -98,6 +104,7 @@ in
xdg.configFile."sway/config.d/custom-keybindings.conf".source = ./config/config.d/custom-keybindings.conf; xdg.configFile."sway/config.d/custom-keybindings.conf".source = ./config/config.d/custom-keybindings.conf;
xdg.configFile."sway/config.d/applications.conf".source = ./config/config.d/applications.conf; xdg.configFile."sway/config.d/applications.conf".source = ./config/config.d/applications.conf;
xdg.configFile."sway/config.d/systemd.conf".source = ./config/config.d/systemd.conf; xdg.configFile."sway/config.d/systemd.conf".source = ./config/config.d/systemd.conf;
xdg.configFile."wayvnc/config".text = import ./config/wayvnc/config.nix { inherit psCfg; inherit pkgs; };
}; };
}) })
]); ]);

View file

@ -41,6 +41,7 @@ in
type = types.nullOr types.str; type = types.nullOr types.str;
default = null; default = null;
}; };
autologin = mkEnableOption "Autologin the pub solar user on all TTYs";
}; };
}; };
} }

View file

@ -2,7 +2,9 @@
with lib; with lib;
let cfg = config.pub-solar.x-os; let
psCfg = config.pub-solar;
cfg = psCfg.x-os;
in in
{ {
options.pub-solar.x-os = { options.pub-solar.x-os = {
@ -34,21 +36,51 @@ in
# These entries get added to /etc/hosts # These entries get added to /etc/hosts
networking.hosts = { networking.hosts = {
"127.0.0.1" = [ "cups.local" ]; "127.0.0.1" = mkIf psCfg.printing.enable [ "cups.local" ];
}; };
# Caddy reverse proxy for local services like cups # ha reverse proxy for local services like cups
services.caddy = { services.haproxy.enable = true;
enable = true; services.haproxy.config = ''
config = '' global
{ maxconn 4096
auto_https off # user http
} # group http
cups.local:80 daemon
bind 127.0.0.1
request_header Host localhost:631 defaults
reverse_proxy unix//run/cups/cups.sock log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
maxconn 2000
timeout connect 5000
timeout client 50000
timeout server 50000
log 127.0.0.1 local0
log 127.0.0.1 local7 debug
option httpchk
frontend http
bind 0.0.0.0:80
acl is_cups hdr_end(host) -i cups.local
acl is_local dst 127.0.0.1
use_backend cups if is_cups is_local
frontend vnc
bind 0.0.0.0:5901
mode tcp
use_backend vnc
backend cups
server cups unix@/run/cups/cups.sock
backend vnc
server vnc unix@/run/wayvnc.sock
''; '';
}; };
};
} }