nixos-config/modules/home-manager/_private/state/ports.nix

60 lines
1.5 KiB
Nix
Raw Normal View History

{ lib, ... }:
2025-01-29 04:48:19 +00:00
let supportedProtocols = [ "tcp" "udp" ];
in {
options.state = let
portRangeType = {
options = {
from = lib.mkOption {
type = lib.types.port;
description = ''
The start of the range of TCP/UDP ports to be taken over.
'';
};
2025-01-29 04:48:19 +00:00
to = lib.mkOption {
type = lib.types.port;
description = ''
The end of the range of TCP/UDP ports to be taken over.
'';
};
};
2025-01-29 04:48:19 +00:00
};
2025-01-29 04:48:19 +00:00
portValueModule = { lib, ... }: {
options = {
protocols = lib.mkOption {
type = with lib.types; listOf (enum supportedProtocols);
description = ''
Indicates the type of protocol of the service.
'';
default = [ "tcp" "udp" ];
example = [ "tcp" ];
};
2025-01-29 04:48:19 +00:00
value = lib.mkOption {
type = with lib.types; either port (submodule portRangeType);
description = ''
The port number itself.
'';
};
};
2025-01-29 04:48:19 +00:00
};
2025-01-29 04:48:19 +00:00
portsSubmodule = { lib, ... }: {
options = {
ports = lib.mkOption {
type = with lib.types; attrsOf (submodule portValueModule);
default = { };
example = lib.literalExpression ''
{
gonic.value = 4629;
mopidy.value = 6034;
}
'';
};
};
};
2025-01-29 04:48:19 +00:00
in lib.mkOption { type = lib.types.submodule portsSubmodule; };
}