modules/lan-mouse: add settings and disable by default

This commit is contained in:
Dmitriy Pleshevskiy 2024-04-16 13:14:23 +03:00
parent df41cd9697
commit e3fae636e9
Signed by: pleshevskiy
GPG key ID: 17041163DA10A9A2
7 changed files with 108 additions and 12 deletions

View file

@ -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))))

Binary file not shown.

View file

@ -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;
};
};
};
}

BIN
hosts/home/data.secret.nix Normal file

Binary file not shown.

View file

@ -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;

View file

@ -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;
};

View file

@ -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";
};
};
################################################################################