nixos/modules/services/xrdp.nix

70 lines
2.3 KiB
Nix
Raw Normal View History

2023-09-05 17:17:43 +08:00
inputs:
{
options.nixos.services.xrdp = let inherit (inputs.lib) mkOption types; in
{
enable = mkOption { type = types.bool; default = false; };
port = mkOption { type = types.ints.unsigned; default = 3389; };
2023-11-16 15:51:47 +08:00
hostname = mkOption { type = types.nullOr (types.nonEmptyListOf types.nonEmptyStr); default = null; };
2024-03-04 20:58:44 +08:00
optimise =
{
type = mkOption { type = types.nullOr (types.enum [ "nvidia" "glamor" ]); default = null; };
2024-03-04 20:58:44 +08:00
nvidiaBusId = mkOption { type = types.nullOr types.nonEmptyStr; default = null; };
};
2023-09-05 17:17:43 +08:00
};
config =
let
inherit (inputs.lib) mkMerge mkIf;
inherit (inputs.config.nixos.services) xrdp;
2023-09-05 20:10:46 +08:00
in mkIf xrdp.enable (mkMerge
2023-09-05 17:17:43 +08:00
[
2024-03-04 18:29:39 +08:00
{
assertions =
2024-03-04 20:58:44 +08:00
[
{
assertion = !inputs.config.nixos.system.envfs.enable;
message = "Somehow xrdp could not start if envfs is enabled";
}
{
assertion = (xrdp.optimise.type == "nvidia") -> (xrdp.optimise.nvidiaBusId != null);
message = "nvidiaBusId must be set if optimise type is nvidia";
}
];
2024-03-04 18:29:39 +08:00
}
2023-09-05 17:17:43 +08:00
{
services.xrdp =
2024-03-01 18:49:14 +08:00
{
enable = true;
2024-03-11 15:17:30 +08:00
package = mkIf (xrdp.optimise.type != null) (inputs.pkgs.xrdp.override
{
variant = xrdp.optimise.type;
inherit (xrdp.optimise) nvidiaBusId;
nvidiaPackage = inputs.config.hardware.nvidia.package;
});
2024-03-01 18:49:14 +08:00
port = xrdp.port;
openFirewall = true;
2024-03-04 18:29:39 +08:00
defaultWindowManager = "${inputs.pkgs.plasma-workspace}/bin/startplasma-x11";
2024-03-01 18:49:14 +08:00
};
2024-03-11 21:59:14 +08:00
environment.etc.xrdp.source = "${inputs.config.services.xrdp.package}/etc/xrdp";
2023-09-05 17:17:43 +08:00
}
(
mkIf (xrdp.hostname != null)
2023-09-13 21:19:08 +08:00
(
let
2023-11-09 22:19:37 +08:00
mainDomain = builtins.elemAt xrdp.hostname 0;
2023-09-13 21:19:08 +08:00
in
{
2023-11-09 22:19:37 +08:00
services.xrdp =
let keydir = inputs.config.security.acme.certs.${mainDomain}.directory;
in { sslCert = "${keydir}/full.pem"; sslKey = "${keydir}/key.pem"; };
nixos.services.acme =
{
enable = true;
cert.${mainDomain} =
2023-11-16 15:51:47 +08:00
{ domains = xrdp.hostname; group = inputs.config.systemd.services.xrdp.serviceConfig.Group; };
2023-11-09 22:19:37 +08:00
};
2023-09-13 21:19:08 +08:00
}
)
2023-09-05 17:17:43 +08:00
)
2023-09-05 20:10:46 +08:00
]);
2023-09-05 17:17:43 +08:00
}