mirror of
https://codeberg.org/icewind/tasproxy.git
synced 2026-06-03 18:24:08 +02:00
fmt:
This commit is contained in:
parent
745376df6f
commit
e9a16ce546
5 changed files with 56 additions and 46 deletions
13
README.md
13
README.md
|
|
@ -8,7 +8,8 @@ Remembering what ip addresses all of your tasmota devices is a pain.
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
Ensure your tasmota devices are connected to an MQTT server with the following "Full Topic":
|
Ensure your tasmota devices are connected to an MQTT server with the following
|
||||||
|
"Full Topic":
|
||||||
|
|
||||||
%prefix%/%topic%/
|
%prefix%/%topic%/
|
||||||
|
|
||||||
|
|
@ -22,12 +23,16 @@ Run the binary with the following environment variables
|
||||||
- `MQTT_PASSWORD`: password to authenticate against the mqtt server
|
- `MQTT_PASSWORD`: password to authenticate against the mqtt server
|
||||||
- `PORT`: port this binary MQTT listen on, defaults to 80
|
- `PORT`: port this binary MQTT listen on, defaults to 80
|
||||||
|
|
||||||
You can also configure the proxy to send HTTP Basic authentication to the tasmota devices by setting the `TASMOTA_USERNAME` and `TASMOTA_PASSWORD` environment variables.
|
You can also configure the proxy to send HTTP Basic authentication to the
|
||||||
|
tasmota devices by setting the `TASMOTA_USERNAME` and `TASMOTA_PASSWORD`
|
||||||
|
environment variables.
|
||||||
|
|
||||||
Setup dns/hosts/etc to point `*.example.com` to the server running this binary
|
Setup dns/hosts/etc to point `*.example.com` to the server running this binary
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
The proxy server will use MQTT to discover and gather the ip addresses of your tasmota devices.
|
The proxy server will use MQTT to discover and gather the ip addresses of your
|
||||||
|
tasmota devices.
|
||||||
|
|
||||||
Any request made to `%hostname%.example.com` will be proxied to the tasmota device with the corresponding topic.
|
Any request made to `%hostname%.example.com` will be proxied to the tasmota
|
||||||
|
device with the corresponding topic.
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
{ dockerTools
|
{
|
||||||
, tasproxy
|
dockerTools,
|
||||||
|
tasproxy,
|
||||||
}:
|
}:
|
||||||
dockerTools.buildLayeredImage {
|
dockerTools.buildLayeredImage {
|
||||||
name = "icewind1991/tasproxy";
|
name = "icewind1991/tasproxy";
|
||||||
|
|
@ -10,9 +11,9 @@ dockerTools.buildLayeredImage {
|
||||||
dockerTools.caCertificates
|
dockerTools.caCertificates
|
||||||
];
|
];
|
||||||
config = {
|
config = {
|
||||||
Cmd = [ "tasproxy" ];
|
Cmd = ["tasproxy"];
|
||||||
ExposedPorts = {
|
ExposedPorts = {
|
||||||
"80/tcp" = { };
|
"80/tcp" = {};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
50
module.nix
50
module.nix
|
|
@ -1,30 +1,32 @@
|
||||||
{ config
|
{
|
||||||
, lib
|
config,
|
||||||
, pkgs
|
lib,
|
||||||
, ...
|
pkgs,
|
||||||
|
...
|
||||||
}:
|
}:
|
||||||
with lib; let
|
with lib; let
|
||||||
cfg = config.services.tasproxy;
|
cfg = config.services.tasproxy;
|
||||||
format = pkgs.formats.toml { };
|
format = pkgs.formats.toml {};
|
||||||
configFile = format.generate "tasproxy-config.toml" {
|
configFile = format.generate "tasproxy-config.toml" {
|
||||||
listen = {
|
listen = {
|
||||||
inherit (cfg) socket;
|
inherit (cfg) socket;
|
||||||
};
|
};
|
||||||
mqtt = {
|
mqtt =
|
||||||
inherit (cfg.mqtt) hostname port;
|
{
|
||||||
} // (
|
inherit (cfg.mqtt) hostname port;
|
||||||
optionalAttrs (cfg.mqtt.passwordFile != null) {
|
|
||||||
inherit (cfg.mqtt) username;
|
|
||||||
password_file = "$CREDENTIALS_DIRECTORY/mqtt_password";
|
|
||||||
}
|
}
|
||||||
);
|
// (
|
||||||
|
optionalAttrs (cfg.mqtt.passwordFile != null) {
|
||||||
|
inherit (cfg.mqtt) username;
|
||||||
|
password_file = "$CREDENTIALS_DIRECTORY/mqtt_password";
|
||||||
|
}
|
||||||
|
);
|
||||||
tasmota = optionalAttrs (cfg.tasmota.username != null) {
|
tasmota = optionalAttrs (cfg.tasmota.username != null) {
|
||||||
inherit (cfg.tasmota) username;
|
inherit (cfg.tasmota) username;
|
||||||
password_file = "$CREDENTIALS_DIRECTORY/tasmota_password";
|
password_file = "$CREDENTIALS_DIRECTORY/tasmota_password";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
in
|
in {
|
||||||
{
|
|
||||||
options.services.tasproxy = {
|
options.services.tasproxy = {
|
||||||
enable = mkEnableOption "Log archiver";
|
enable = mkEnableOption "Log archiver";
|
||||||
|
|
||||||
|
|
@ -81,7 +83,7 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
default = { };
|
default = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
enableUnixSocket = mkOption {
|
enableUnixSocket = mkOption {
|
||||||
|
|
@ -99,14 +101,16 @@ in
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
systemd.services."tasproxy" = {
|
systemd.services."tasproxy" = {
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = ["multi-user.target"];
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
LoadCredential = (optional (cfg.mqtt.passwordFile != null) [
|
LoadCredential =
|
||||||
"mqtt_password:${cfg.mqtt.passwordFile}"
|
(optional (cfg.mqtt.passwordFile != null) [
|
||||||
]) ++ (optional (cfg.tasmota.passwordFile != null) [
|
"mqtt_password:${cfg.mqtt.passwordFile}"
|
||||||
"tasmota_password:${cfg.tasmota.passwordFile}"
|
])
|
||||||
]);
|
++ (optional (cfg.tasmota.passwordFile != null) [
|
||||||
|
"tasmota_password:${cfg.tasmota.passwordFile}"
|
||||||
|
]);
|
||||||
|
|
||||||
ExecStart = "${cfg.package}/bin/tasproxy ${configFile}";
|
ExecStart = "${cfg.package}/bin/tasproxy ${configFile}";
|
||||||
|
|
||||||
|
|
@ -128,10 +132,10 @@ in
|
||||||
ProtectHostname = true;
|
ProtectHostname = true;
|
||||||
LockPersonality = true;
|
LockPersonality = true;
|
||||||
ProtectKernelTunables = true;
|
ProtectKernelTunables = true;
|
||||||
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ] ++ optionals cfg.enableUnixSocket [ "AF_UNIX" ];
|
RestrictAddressFamilies = ["AF_INET" "AF_INET6"] ++ optionals cfg.enableUnixSocket ["AF_UNIX"];
|
||||||
RestrictRealtime = true;
|
RestrictRealtime = true;
|
||||||
ProtectProc = "noaccess";
|
ProtectProc = "noaccess";
|
||||||
SystemCallFilter = [ "@system-service" "~@resources" "~@privileged" ];
|
SystemCallFilter = ["@system-service" "~@resources" "~@privileged"];
|
||||||
IPAddressDeny = "multicast";
|
IPAddressDeny = "multicast";
|
||||||
PrivateUsers = true;
|
PrivateUsers = true;
|
||||||
ProcSubset = "pid";
|
ProcSubset = "pid";
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
final: prev: {
|
final: prev: {
|
||||||
tasproxy = final.callPackage ./package.nix { };
|
tasproxy = final.callPackage ./package.nix {};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
28
package.nix
28
package.nix
|
|
@ -1,18 +1,18 @@
|
||||||
{ stdenv
|
{
|
||||||
, rustPlatform
|
stdenv,
|
||||||
, lib
|
rustPlatform,
|
||||||
}:
|
lib,
|
||||||
let
|
}: let
|
||||||
inherit (lib.sources) sourceByRegex;
|
inherit (lib.sources) sourceByRegex;
|
||||||
src = sourceByRegex ./. [ "Cargo.*" "(src)(/.*)?" ];
|
src = sourceByRegex ./. ["Cargo.*" "(src)(/.*)?"];
|
||||||
in
|
in
|
||||||
rustPlatform.buildRustPackage rec {
|
rustPlatform.buildRustPackage rec {
|
||||||
pname = "tasproxy";
|
pname = "tasproxy";
|
||||||
version = "0.1.0";
|
version = "0.1.0";
|
||||||
|
|
||||||
inherit src;
|
inherit src;
|
||||||
|
|
||||||
cargoLock = {
|
cargoLock = {
|
||||||
lockFile = ./Cargo.lock;
|
lockFile = ./Cargo.lock;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue