2023-11-16 04:20:00 +00:00
|
|
|
{ options, config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
opt = options.services.rkvm;
|
|
|
|
cfg = config.services.rkvm;
|
|
|
|
toml = pkgs.formats.toml { };
|
|
|
|
in
|
|
|
|
{
|
2024-07-31 10:19:44 +00:00
|
|
|
meta.maintainers = [ ];
|
2023-11-16 04:20:00 +00:00
|
|
|
|
|
|
|
options.services.rkvm = {
|
|
|
|
enable = mkOption {
|
|
|
|
default = cfg.server.enable || cfg.client.enable;
|
|
|
|
defaultText = literalExpression "config.${opt.server.enable} || config.${opt.client.enable}";
|
|
|
|
type = types.bool;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-11-16 04:20:00 +00:00
|
|
|
Whether to enable rkvm, a Virtual KVM switch for Linux machines.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
package = mkPackageOption pkgs "rkvm" { };
|
|
|
|
|
|
|
|
server = {
|
|
|
|
enable = mkEnableOption "the rkvm server daemon (input transmitter)";
|
|
|
|
|
|
|
|
settings = mkOption {
|
|
|
|
type = types.submodule
|
|
|
|
{
|
|
|
|
freeformType = toml.type;
|
|
|
|
options = {
|
|
|
|
listen = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "0.0.0.0:5258";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-11-16 04:20:00 +00:00
|
|
|
An internet socket address to listen on, either IPv4 or IPv6.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
switch-keys = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ "left-alt" "left-ctrl" ];
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-11-16 04:20:00 +00:00
|
|
|
A key list specifying a host switch combination.
|
|
|
|
|
|
|
|
_A list of key names is available in <https://github.com/htrefil/rkvm/blob/master/switch-keys.md>._
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
certificate = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/etc/rkvm/certificate.pem";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-11-16 04:20:00 +00:00
|
|
|
TLS certificate path.
|
|
|
|
|
|
|
|
::: {.note}
|
|
|
|
This should be generated with {command}`rkvm-certificate-gen`.
|
|
|
|
:::
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
key = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/etc/rkvm/key.pem";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-11-16 04:20:00 +00:00
|
|
|
TLS key path.
|
|
|
|
|
|
|
|
::: {.note}
|
|
|
|
This should be generated with {command}`rkvm-certificate-gen`.
|
|
|
|
:::
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
password = mkOption {
|
|
|
|
type = types.str;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-11-16 04:20:00 +00:00
|
|
|
Shared secret token to authenticate the client.
|
|
|
|
Make sure this matches your client's config.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
default = { };
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Structured server daemon configuration";
|
2023-11-16 04:20:00 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
client = {
|
|
|
|
enable = mkEnableOption "the rkvm client daemon (input receiver)";
|
|
|
|
|
|
|
|
settings = mkOption {
|
|
|
|
type = types.submodule
|
|
|
|
{
|
|
|
|
freeformType = toml.type;
|
|
|
|
options = {
|
|
|
|
server = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "192.168.0.123:5258";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-11-16 04:20:00 +00:00
|
|
|
An RKVM server's internet socket address, either IPv4 or IPv6.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
certificate = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/etc/rkvm/certificate.pem";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-11-16 04:20:00 +00:00
|
|
|
TLS ceritficate path.
|
|
|
|
|
|
|
|
::: {.note}
|
|
|
|
This should be generated with {command}`rkvm-certificate-gen`.
|
|
|
|
:::
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
password = mkOption {
|
|
|
|
type = types.str;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-11-16 04:20:00 +00:00
|
|
|
Shared secret token to authenticate the client.
|
|
|
|
Make sure this matches your server's config.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
default = {};
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Structured client daemon configuration";
|
2023-11-16 04:20:00 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
|
|
|
|
systemd.services =
|
|
|
|
let
|
|
|
|
mkBase = component: {
|
|
|
|
description = "RKVM ${component}";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = {
|
|
|
|
server = [ "network.target" ];
|
|
|
|
client = [ "network-online.target" ];
|
|
|
|
}.${component};
|
|
|
|
wants = {
|
|
|
|
server = [ ];
|
|
|
|
client = [ "network-online.target" ];
|
|
|
|
}.${component};
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${cfg.package}/bin/rkvm-${component} ${toml.generate "rkvm-${component}.toml" cfg.${component}.settings}";
|
|
|
|
Restart = "always";
|
|
|
|
RestartSec = 5;
|
|
|
|
Type = "simple";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
rkvm-server = mkIf cfg.server.enable (mkBase "server");
|
|
|
|
rkvm-client = mkIf cfg.client.enable (mkBase "client");
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|