system/modules/home-manager/services/lan-mouse/default.nix

87 lines
2.1 KiB
Nix
Raw Normal View History

{ config, pkgs, lib, ... }:
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;
};
};
});
# See: https://github.com/feschber/lan-mouse/blob/main/src/config.rs#L79
lanMouseConfig = pkgs.writeText "config.toml" (
let
# List[str] -> str
2024-04-16 17:59:16 +03:00
listOfStr = lib.concatMapStringsSep "," (val: "\"${val}\"");
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"}
''
))
)
);
in
{
options.local.services.lan-mouse = with lib; {
enable = mkEnableOption "lan-mouse";
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;
package = pkgs.unstable.lan-mouse;
};
xdg.configFile."lan-mouse/config.toml".source = lanMouseConfig;
};
}