This commit is contained in:
Robin Appelman 2026-03-26 16:29:00 +01:00
commit c3b5238a51
13 changed files with 532 additions and 603 deletions

19
nix/docker.nix Normal file
View file

@ -0,0 +1,19 @@
{
dockerTools,
taspromto,
}:
dockerTools.buildLayeredImage {
name = "icewind1991/taspromto";
tag = "latest";
maxLayers = 5;
contents = [
taspromto
dockerTools.caCertificates
];
config = {
Cmd = ["taspromto"];
ExposedPorts = {
"80/tcp" = {};
};
};
}

125
nix/module.nix Normal file
View file

@ -0,0 +1,125 @@
{
config,
lib,
pkgs,
...
}:
with lib; let
cfg = config.services.taspromto;
format = pkgs.formats.toml {};
configFile = format.generate "taspromto-config.toml" {
listen = {
inherit (cfg) port;
};
names = {
mitemp = cfg.mitempNames;
rftemp = cfg.rfChannelNames;
};
mqtt =
{
inherit (cfg.mqtt) hostname port;
}
// (
optionalAttrs (cfg.mqtt.passwordFile != null) {
inherit (cfg.mqtt) username;
password_file = "$CREDENTIALS_DIRECTORY/mqtt_password";
}
);
};
in {
options.services.taspromto = {
enable = mkEnableOption "taspromto";
mitempNames = mkOption {
type = types.attrs;
default = {};
description = "Names for mitemp sensors";
};
rfChannelNames = mkOption {
type = types.attrs;
default = {};
description = "Names for 433mhz temperature sensors";
};
port = mkOption {
type = types.port;
default = 3030;
description = "port to listen to";
};
mqtt = mkOption {
type = types.submodule {
options = {
hostname = mkOption {
type = types.str;
description = "Hostname of the MQTT server";
};
port = mkOption {
type = types.port;
default = 1883;
description = "Port of the MQTT server";
};
username = mkOption {
type = types.nullOr types.str;
default = null;
description = "Username for the MQTT server";
};
passwordFile = mkOption {
type = types.nullOr types.str;
default = null;
description = "File containing the password for the MQTT server";
};
};
};
};
package = mkOption {
type = types.package;
defaultText = literalExpression "pkgs.taspromto";
description = "package to use";
};
};
config = mkIf cfg.enable {
systemd.services."taspromto" = {
wantedBy = ["multi-user.target"];
serviceConfig = {
LoadCredential = optional (cfg.mqtt.passwordFile != null) [
"mqtt_password:${cfg.mqtt.passwordFile}"
];
ExecStart = "${cfg.package}/bin/taspromto ${configFile}";
Restart = "on-failure";
DynamicUser = true;
PrivateTmp = true;
ProtectSystem = "strict";
ProtectHome = true;
NoNewPrivileges = true;
PrivateDevices = true;
ProtectClock = true;
CapabilityBoundingSet = true;
ProtectKernelLogs = true;
ProtectControlGroups = true;
SystemCallArchitectures = "native";
ProtectKernelModules = true;
RestrictNamespaces = true;
MemoryDenyWriteExecute = true;
ProtectHostname = true;
LockPersonality = true;
ProtectKernelTunables = true;
RestrictAddressFamilies = ["AF_INET" "AF_INET6" "AF_UNIX"];
RuntimeDirectory = "taspromto";
RestrictRealtime = true;
ProtectProc = "noaccess";
SystemCallFilter = ["@system-service" "~@resources" "~@privileged"];
IPAddressDeny = "any";
IPAddressAllow = ["localhost" cfg.mqtt.hostname];
PrivateUsers = true;
ProcSubset = "pid";
};
};
};
}

3
nix/overlay.nix Normal file
View file

@ -0,0 +1,3 @@
final: prev: {
taspromto = final.callPackage ./package.nix {};
}

20
nix/package.nix Normal file
View file

@ -0,0 +1,20 @@
{
stdenv,
rustPlatform,
lib,
}: let
inherit (lib.sources) sourceByRegex;
inherit (builtins) fromTOML readFile;
src = sourceByRegex ../. ["Cargo.*" "(src)(/.*)?"];
version = (fromTOML (readFile ../Cargo.toml)).package.version;
in
rustPlatform.buildRustPackage rec {
pname = "taspromto";
inherit src version;
cargoLock = {
lockFile = ../Cargo.lock;
};
meta.mainProgram = "taspromto";
}