2024-04-16 11:28:28 +03:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.local.services.lan-mouse;
|
|
|
|
|
2024-04-16 13:14:23 +03:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2024-04-16 11:28:28 +03:00
|
|
|
# See: https://github.com/feschber/lan-mouse/blob/main/src/config.rs#L79
|
2024-04-16 13:14:23 +03:00
|
|
|
lanMouseConfig = pkgs.writeText "config.toml" (
|
|
|
|
let
|
|
|
|
# List[str] -> str
|
2024-04-16 17:59:16 +03:00
|
|
|
listOfStr = lib.concatMapStringsSep "," (val: "\"${val}\"");
|
2024-04-16 13:14:23 +03:00
|
|
|
in
|
|
|
|
''
|
|
|
|
port = ${toString cfg.settings.port}
|
|
|
|
frontent = "${cfg.settings.frontend}"
|
|
|
|
''
|
|
|
|
+ lib.optionalString (cfg.settings.releaseBind != [ ]) ''
|
|
|
|
release_bind = [${listOfStr cfg.settings.releaseBind}]
|
|
|
|
''
|
2024-04-16 17:59:16 +03:00
|
|
|
+ (builtins.concatStringsSep "\n"
|
|
|
|
(lib.flip lib.mapAttrstoList cfg.settings.connections (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"}
|
|
|
|
''
|
|
|
|
))
|
2024-04-16 13:14:23 +03:00
|
|
|
)
|
|
|
|
);
|
2024-04-16 11:28:28 +03:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options.local.services.lan-mouse = with lib; {
|
|
|
|
enable = mkEnableOption "lan-mouse";
|
2024-04-16 13:14:23 +03:00
|
|
|
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 = { };
|
|
|
|
};
|
2024-04-16 11:28:28 +03:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
programs.lan-mouse = {
|
|
|
|
enable = true;
|
2024-04-16 13:14:23 +03:00
|
|
|
# systemd = true;
|
2024-04-16 11:28:28 +03:00
|
|
|
package = pkgs.unstable.lan-mouse;
|
|
|
|
};
|
|
|
|
|
|
|
|
xdg.configFile."lan-mouse/config.toml".source = lanMouseConfig;
|
|
|
|
};
|
|
|
|
}
|