mirror of
https://github.com/Gerg-L/nixos.git
synced 2025-12-10 00:43:56 -05:00
port magic
This commit is contained in:
parent
7dad855bd8
commit
c7c87ec8b2
8 changed files with 144 additions and 73 deletions
|
|
@ -59,7 +59,6 @@
|
|||
#
|
||||
#allow-import-from-derivation = false;
|
||||
trusted-users = [ "root" ];
|
||||
allowed-users = [ "@wheel" ];
|
||||
use-xdg-base-directories = true;
|
||||
auto-allocate-uids = true;
|
||||
};
|
||||
|
|
|
|||
94
nixosModules/portMagic.nix
Normal file
94
nixosModules/portMagic.nix
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
{ lib, ... }:
|
||||
{
|
||||
options.local.links = lib.mkOption {
|
||||
type = lib.types.attrsOf (
|
||||
lib.types.submodule (
|
||||
{
|
||||
config,
|
||||
name,
|
||||
...
|
||||
}:
|
||||
|
||||
let
|
||||
portHash = lib.flip lib.pipe [
|
||||
(builtins.hashString "md5")
|
||||
(builtins.substring 0 7)
|
||||
(hash: (fromTOML "v=0x${hash}").v)
|
||||
(lib.flip lib.mod config.reservedPorts.amount)
|
||||
(builtins.add config.reservedPorts.start)
|
||||
];
|
||||
in
|
||||
|
||||
{
|
||||
options = {
|
||||
ipv4 = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "127.0.0.1";
|
||||
description = "The IPv4 address.";
|
||||
};
|
||||
hostname = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = "The hostname.";
|
||||
};
|
||||
|
||||
port = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
description = "The TCP or UDP port.";
|
||||
};
|
||||
portStr = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = "The TCP or UDP port, as a string.";
|
||||
};
|
||||
reservedPorts = {
|
||||
amount = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
default = 10000;
|
||||
description = "Amount of ports to reserve at most.";
|
||||
};
|
||||
start = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
default = 30000;
|
||||
description = "Starting point for reserved ports.";
|
||||
};
|
||||
};
|
||||
|
||||
protocol = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "http";
|
||||
description = "The protocol in URL scheme name format.";
|
||||
};
|
||||
path = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.path;
|
||||
default = null;
|
||||
description = "The resource path.";
|
||||
};
|
||||
url = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = "The URL.";
|
||||
};
|
||||
tuple = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = "The hostname:port tuple.";
|
||||
};
|
||||
extra = lib.mkOption {
|
||||
type = lib.types.attrs;
|
||||
description = "Arbitrary extra data.";
|
||||
};
|
||||
};
|
||||
config = lib.mkIf true {
|
||||
hostname = lib.mkDefault config.ipv4;
|
||||
port = lib.mkDefault (portHash "${config.hostname}:${name}");
|
||||
portStr = toString config.port;
|
||||
tuple = "${config.hostname}:${config.portStr}";
|
||||
url = "${config.protocol}://${config.hostname}:${config.portStr}${
|
||||
if config.path == null then "" else config.path
|
||||
}";
|
||||
};
|
||||
}
|
||||
)
|
||||
|
||||
);
|
||||
description = "Port Magic links.";
|
||||
default = { };
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue