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 0000000..74e6522 Binary files /dev/null and b/hosts/asus-gl553vd/data.secret.nix differ 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 0000000..b632744 Binary files /dev/null and b/hosts/home/data.secret.nix differ 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"; + }; }; ################################################################################