modules/rtlamr2mqtt: init

- run on pwntie
- remove unused stuff from box
-
This commit is contained in:
Aaron Bieber 2023-08-17 15:43:16 -06:00
parent fbcbab9c09
commit 68b68e8fd4
No known key found for this signature in database
5 changed files with 170 additions and 14 deletions

View File

@ -295,6 +295,9 @@
precursorupdater = spkgs.python3Packages.callPackage ./pkgs/precursorupdater.nix {
inherit spkgs;
};
rtlamr2mqtt = spkgs.python3Packages.callPackage ./pkgs/rtlamr2mqtt.nix {
inherit spkgs;
};
kobuddy = upkgs.python3Packages.callPackage ./pkgs/kobuddy.nix {
inherit upkgs;
};

View File

@ -44,12 +44,6 @@
owner = config.users.users.nginx.name;
mode = "400";
};
rtlamr2mqtt = pkgs.fetchFromGitHub {
owner = "allangood";
repo = "rtlamr2mqtt";
rev = "b2b05b9c16c396790913fd6f2ff11d5afdef4de8";
hash = "sha256-bm348peVASsApjH+tUyFeF/gXltUNhssT7o+z20qnCc=";
};
in {
_module.args.isUnstable = false;
imports = [
@ -57,11 +51,6 @@ in {
"${inputs.unstable}/nixos/modules/services/home-automation/home-assistant.nix"
];
systemd.tmpfiles.rules = [
"C /var/lib/hass/custom_components/rtlamr2mqtt - - - - ${rtlamr2mqtt}"
"Z /var/lib/hass/custom_components 770 hass hass - -"
];
sops.secrets = {
#nextcloud_db_pass = {
# owner = config.users.users.nextcloud.name;
@ -184,7 +173,7 @@ in {
nixpkgs = {
config.allowUnfree = true;
overlays = [
(self: super: {
(_: _: {
inherit (inputs.unstable.legacyPackages.${pkgs.system}) home-assistant;
})
];

View File

@ -1,11 +1,18 @@
{pkgs, ...}: let
{
pkgs,
config,
...
}: let
#myEmacs = pkgs.callPackage ../../configs/emacs.nix { };
pubKeys = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIO7v+/xS8832iMqJHCWsxUZ8zYoMWoZhjj++e26g1fLT europa"
];
in {
_module.args.isUnstable = false;
imports = [./hardware-configuration.nix];
imports = [
./hardware-configuration.nix
../../modules/rtlamr2mqtt.nix
];
hardware.rtl-sdr.enable = true;
@ -65,6 +72,40 @@ in {
};
services = {
rtlamr2mqtt = {
enable = true;
configuration = {
general = {
device_ids_path = "${config.services.rtlamr2mqtt.package}/sdl_ids.txt";
sleep_for = 0;
verbosity = "debug";
tickle_rtl_tcp = false;
device_id = "0bda:2838";
};
mqtt = {
host = "10.6.0.15";
port = 1883;
tls_enabled = false;
ha_autodiscovery = true;
base_topec = "rtlamr";
};
custom_parameters = {
rtltcp = "-s 2048000";
rtlamr = "-unique=true -symbollength=32";
};
meters = [
{
id = 48582066;
protocol = "scm";
name = "gas_meter";
unit_of_measurement = "ft³";
icon = "mdi:gas-burner";
device_class = "gas";
state_class = "total_increasing";
}
];
};
};
#emacs = {
# enable = true;
# package = myEmacs;

81
modules/rtlamr2mqtt.nix Normal file
View File

@ -0,0 +1,81 @@
{
config,
lib,
pkgs,
...
}:
with pkgs; let
cfg = config.services.rtlamr2mqtt;
rtlamr2mqtt = pkgs.python3Packages.callPackage ../pkgs/rtlamr2mqtt.nix {};
settingsFormat = pkgs.formats.json {};
settingsType = settingsFormat.type;
prettyJSON = conf:
pkgs.runCommandLocal "rtlamr2mqtt-config.json" {} ''
echo '${
builtins.toJSON conf
}' | ${pkgs.buildPackages.jq}/bin/jq 'del(._module)' > $out
'';
in {
options = with lib; {
services.rtlamr2mqtt = {
enable = mkEnableOption "Enable rtlamr2mqtt";
user = mkOption {
type = with types; oneOf [str int];
default = "rtlamr2mqtt";
description = ''
The user the service will use.
'';
};
group = mkOption {
type = with types; oneOf [str int];
default = "rtlamr2mqtt";
description = ''
The user the service will use.
'';
};
configuration = mkOption {
type = settingsType;
description = ''
Specify the configuration for rtlamr2mqtt in Nix.
'';
};
package = mkOption {
type = types.package;
default = rtlamr2mqtt;
defaultText = literalExpression "pkgs.rtlamr2mqtt";
description = "The package to use for rtlamr2mqtt";
};
};
};
config = lib.mkIf cfg.enable {
users.groups.rtlamr2mqtt = {};
users.users.rtlamr2mqtt = {
description = "rtlamr2mqtt service user";
isSystemUser = true;
home = "/var/lib/rtlamr2mqtt";
createHome = true;
group = "rtlamr2mqtt";
extraGroups = ["plugdev"];
};
systemd.services.rtlamr2mqtt = {
enable = true;
description = "rtlamr2mqtt server";
wantedBy = ["multi-user.target"];
serviceConfig = {
User = cfg.user;
Group = cfg.group;
RuntimeDirectory = "/var/lib/rtlamr2mqtt";
ExecStart = "${cfg.package}/bin/rtlamr2mqtt ${prettyJSON cfg.configuration}";
};
};
};
}

42
pkgs/rtlamr2mqtt.nix Normal file
View File

@ -0,0 +1,42 @@
{
buildPythonPackage,
callPackage,
fetchFromGitHub,
paho-mqtt,
pyusb,
pyyaml,
requests,
rtl-sdr,
...
}: let
rtlamr = callPackage ./rtlamr.nix {};
in
buildPythonPackage {
pname = "rtlamr2mqtt";
version = "unstable-2023-08-17";
format = "none";
nativeBuildInputs = [];
propagatedBuildInputs = [paho-mqtt pyyaml requests pyusb rtlamr rtl-sdr];
doCheck = false;
doBuild = false;
installPhase = ''
mkdir -p $out/bin
cp rtlamr2mqtt-addon/rtlamr2mqtt.py $out/bin/rtlamr2mqtt
cp rtlamr2mqtt-addon/sdl_ids.txt $out/
'';
src = fetchFromGitHub {
owner = "qbit";
repo = "rtlamr2mqtt";
hash = "sha256-WqW+RZQhwYAIvBAizO3/7SdlhWR9ZIIliEq76XwsUEo=";
rev = "631504e";
};
meta = {
mainProgram = "rtlamr2mqtt";
};
}