From ad313173ad095885a688e764e2f1a046e4f7b081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20B=C3=A4dorf?= Date: Thu, 28 Apr 2022 23:20:18 +0200 Subject: [PATCH] Add wayvnc option for sway This change allows you to start wayvnc anytime your sway session starts. For hosts where you want to enable this, you'll need to generate the certificate and keys, see: https://github.com/any1/wayvnc#encryption--authentication You can then add these to your secrets via agenix, and load them as `vnc-key.pem` and `vnc-cert.pem` into `/run/secrets`. Enable the wayvnc server via the option `pub-solar.sway.vnc.enable`. At the time of writing, `tigervnc` appears to be a good vnc client to use. ``` --- .../config/config.d/custom-keybindings.conf | 6 ++++++ modules/sway/config/wayvnc/config.nix | 8 ++++++++ modules/sway/default.nix | 15 ++++++++++----- modules/sway/wayvnc.service.nix | 19 +++++++++++++++++++ 4 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 modules/sway/config/wayvnc/config.nix create mode 100644 modules/sway/wayvnc.service.nix diff --git a/modules/sway/config/config.d/custom-keybindings.conf b/modules/sway/config/config.d/custom-keybindings.conf index 5faddece..4a00bd77 100644 --- a/modules/sway/config/config.d/custom-keybindings.conf +++ b/modules/sway/config/config.d/custom-keybindings.conf @@ -47,3 +47,9 @@ mode "$mode_system" { bindsym Return mode "default" bindsym Escape mode "default" } + +set $mode_vncclient In VNCClient mode. Press $mod+Num_Lock to return. +bindsym $mod+Num_Lock mode "$mode_vncclient" +mode "$mode_vncclient" { + bindsym $mod+Num_Lock mode "default" +} diff --git a/modules/sway/config/wayvnc/config.nix b/modules/sway/config/wayvnc/config.nix new file mode 100644 index 00000000..1ecc2e5f --- /dev/null +++ b/modules/sway/config/wayvnc/config.nix @@ -0,0 +1,8 @@ +{ psCfg, pkgs }: " +address=0.0.0.0 +enable_auth=true +username=${psCfg.user.name} +password=${psCfg.user.password} +private_key_file=/run/secrets/vnc-key.pem +certificate_file=/run/secrets/vnc-cert.pem +" diff --git a/modules/sway/default.nix b/modules/sway/default.nix index cfc5733c..568bcb41 100644 --- a/modules/sway/default.nix +++ b/modules/sway/default.nix @@ -7,11 +7,13 @@ in { options.pub-solar.sway = { enable = mkEnableOption "Life in boxes"; - }; - options.pub-solar.sway.v4l2loopback.enable = mkOption { - type = types.bool; - default = true; - description = "WebCam streaming tool"; + vnc.enable = mkEnableOption "Enable vnc service"; + + v4l2loopback.enable = mkOption { + type = types.bool; + default = true; + description = "WebCam streaming tool"; + }; }; config = mkIf cfg.enable (mkMerge [ @@ -76,6 +78,8 @@ in systemd.user.services.waybar = import ./waybar.service.nix pkgs; systemd.user.targets.sway-session = import ./sway-session.target.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; @@ -83,6 +87,7 @@ in 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; }; }; }) ]); diff --git a/modules/sway/wayvnc.service.nix b/modules/sway/wayvnc.service.nix new file mode 100644 index 00000000..0963da5e --- /dev/null +++ b/modules/sway/wayvnc.service.nix @@ -0,0 +1,19 @@ +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"; + ExecStart = "${pkgs.wayvnc}/bin/wayvnc"; + }; + + Install = { + WantedBy = [ "sway-session.target" ]; + }; +}