From e3fae636e9bc78043d3d9791a60ab908240a3fa9 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Tue, 16 Apr 2024 13:14:23 +0300 Subject: [PATCH] modules/lan-mouse: add settings and disable by default --- Makefile | 5 +- hosts/asus-gl553vd/data.secret.nix | Bin 0 -> 78 bytes hosts/asus-gl553vd/users/jan.nix | 13 +++ hosts/home/data.secret.nix | Bin 0 -> 78 bytes hosts/home/users/jan.nix | 13 +++ .../services/lan-mouse/default.nix | 78 ++++++++++++++++-- users/jan/default.nix | 11 ++- 7 files changed, 108 insertions(+), 12 deletions(-) create mode 100644 hosts/asus-gl553vd/data.secret.nix create mode 100644 hosts/home/data.secret.nix diff --git a/Makefile b/Makefile index 79d0ca1..4cecfd6 100644 --- a/Makefile +++ b/Makefile @@ -36,12 +36,13 @@ define machine_rule .PHONY: $(1) $(1): ; systemctl --user reset-failed - sudo nix run $(NIX_ARGS) .#switch/$(1) + sudo nix run $(NIX_ARGS) .#switch/$(1) -- $(BUILD_ARGS) endef define vps_rule .PHONY: $(1) -$(1): ; nix run .#deploy/$(1) +$(1): ; nix run .#deploy/$(1) -- $(BUILD_ARGS) + endef $(foreach machine,$(MACHINES),$(eval $(call machine_rule,$(machine)))) diff --git a/hosts/asus-gl553vd/data.secret.nix b/hosts/asus-gl553vd/data.secret.nix new file mode 100644 index 0000000000000000000000000000000000000000..74e65224c68606aa32f3af1c3deaa03cfd6b31fa GIT binary patch literal 78 zcmV-U0I~l7M@dveQdv+`0HGtjV`GHA-i*8hsR#-8S6t1M;w67{<_({h+yq45r k+Sf6Cnf_6Hb$YAjXb)m6&9~p9ze@aiIxd2hML#+}p?*;%asU7T literal 0 HcmV?d00001 diff --git a/hosts/asus-gl553vd/users/jan.nix b/hosts/asus-gl553vd/users/jan.nix index b898062..7a9b473 100644 --- a/hosts/asus-gl553vd/users/jan.nix +++ b/hosts/asus-gl553vd/users/jan.nix @@ -1,5 +1,9 @@ { ... }: +let + asusData = import ../data.secret.nix; + homeData = import ../../home/data.secret.nix; +in { imports = [ ../../../users/jan ]; @@ -11,5 +15,14 @@ # local.programs.dev-tools.k8s.enable = true; local.programs.libreoffice.enable = true; + + local.services.lan-mouse.settings = { + port = asusData.lan-mouse.port; + connections.left = { + hostname = "home"; + ips = [ homeData.addr ]; + port = homeData.lan-mouse.port; + }; + }; }; } diff --git a/hosts/home/data.secret.nix b/hosts/home/data.secret.nix new file mode 100644 index 0000000000000000000000000000000000000000..b6327442f0564cc11f56cc293dc04a3dc29761a8 GIT binary patch literal 78 zcmV-U0I~l7M@dveQdv+`08FHtF!xyhsES3rY&4=$#YHRP0{qk8XHBtDJEe%HaMK`A k0XD|k7*RP}U5etqX+w|1;n@s3C}n<)!UD#XQRbdA=~P7|i2wiq literal 0 HcmV?d00001 diff --git a/hosts/home/users/jan.nix b/hosts/home/users/jan.nix index 067f77a..21d9e58 100644 --- a/hosts/home/users/jan.nix +++ b/hosts/home/users/jan.nix @@ -1,5 +1,9 @@ { pkgs, ... }: +let + homeData = import ../data.secret.nix; + asusData = import ../../asus-gl553vd/data.secret.nix; +in { imports = [ ../../../users/jan ]; @@ -8,6 +12,15 @@ xmonad.projects = import ./xmonad-projects.secret.nix; }; + local.services.lan-mouse.settings = { + port = homeData.lan-mouse.port; + connections.left = { + hostname = "asus"; + ips = [ asusData.addr ]; + port = asusData.lan-mouse.port; + }; + }; + local.programs.editors.arduino-ide.enable = true; local.programs.dev-tools.k8s.enable = true; diff --git a/modules/home-manager/services/lan-mouse/default.nix b/modules/home-manager/services/lan-mouse/default.nix index 8df9cef..980d2e7 100644 --- a/modules/home-manager/services/lan-mouse/default.nix +++ b/modules/home-manager/services/lan-mouse/default.nix @@ -3,24 +3,88 @@ let cfg = config.local.services.lan-mouse; + connectionSettings = with lib; (types.submodule { + options = { + hostname = mkOption { + type = types.str; + default = ""; + }; + ips = mkOption { + type = types.listOf types.str; + default = [ ]; + }; + port = mkOption { + type = types.int; + default = 4242; + }; + activateOnStartup = mkOption { + type = types.bool; + default = false; + }; + }; + }); + + inherit (builtins) concatStringsSep; + # See: https://github.com/feschber/lan-mouse/blob/main/src/config.rs#L79 - lanMouseConfig = pkgs.writeText "config.toml" '' - port = ${toString cfg.port} - ''; + lanMouseConfig = pkgs.writeText "config.toml" ( + let + # List[str] -> str + listOfStr = l: concatStringsSep "," (map (val: "\"${val}\"") l); + in + '' + port = ${toString cfg.settings.port} + frontent = "${cfg.settings.frontend}" + '' + + lib.optionalString (cfg.settings.releaseBind != [ ]) '' + release_bind = [${listOfStr cfg.settings.releaseBind}] + '' + + (concatStringsSep "\n" + (lib.attrValues + (lib.mapAttrs + (key: value: '' + [${key}] + ips = [${listOfStr value.ips}] + ${lib.optionalString (value.hostname != "") '' + hostname = "${value.hostname}" + ''} + port = ${toString value.port} + activate_on_startup = ${if value.activateOnStartup then "true" else "false"} + '' + ) + cfg.settings.connections + ) + ) + ) + ); in { options.local.services.lan-mouse = with lib; { enable = mkEnableOption "lan-mouse"; - port = mkOption { - type = types.int; - default = 4242; + settings = { + releaseBind = mkOption { + type = types.listOf types.str; + default = [ ]; + }; + frontend = mkOption { + type = types.enum [ "cli" "gtk" ]; + default = "gtk"; + }; + port = mkOption { + type = types.int; + default = 4242; + }; + connections = mkOption { + type = types.attrsOf connectionSettings; + default = { }; + }; }; }; config = lib.mkIf cfg.enable { programs.lan-mouse = { enable = true; - systemd = true; + # systemd = true; package = pkgs.unstable.lan-mouse; }; diff --git a/users/jan/default.nix b/users/jan/default.nix index 91aa1a7..3380066 100644 --- a/users/jan/default.nix +++ b/users/jan/default.nix @@ -35,7 +35,7 @@ networking.firewall.allowedUDPPorts = let lanMouseCfg = config.home-manager.users.jan.local.services.lan-mouse; - in lib.optional lanMouseCfg.enable lanMouseCfg.port; + in lib.optional lanMouseCfg.enable lanMouseCfg.settings.port; home-manager.users.jan = { imports = [ @@ -112,8 +112,13 @@ local.services.wired.enable = lib.mkDefault true; local.services.lan-mouse = { - enable = lib.mkDefault true; - port = lib.mkDefault 32000; + # x11 input capture not available: not implemented + enable = lib.mkDefault false; + settings = { + # releaseBind = [ "KeyLeftCtrl" "KeyLeftShift" "KeyF1" ]; + port = lib.mkDefault 32000; + frontend = "cli"; + }; }; ################################################################################