2023-09-12 08:44:05 -06:00
|
|
|
{ config
|
|
|
|
, lib
|
|
|
|
, pkgs
|
|
|
|
, ...
|
2023-08-17 15:43:16 -06:00
|
|
|
}:
|
|
|
|
with pkgs; let
|
|
|
|
cfg = config.services.rtlamr2mqtt;
|
2023-09-12 08:44:05 -06:00
|
|
|
rtlamr2mqtt = pkgs.python3Packages.callPackage ../pkgs/rtlamr2mqtt.nix { };
|
|
|
|
settingsFormat = pkgs.formats.json { };
|
2023-08-17 15:43:16 -06:00
|
|
|
settingsType = settingsFormat.type;
|
|
|
|
prettyJSON = conf:
|
2023-09-12 08:44:05 -06:00
|
|
|
pkgs.runCommandLocal "rtlamr2mqtt-config.json" { } ''
|
2023-08-17 15:43:16 -06:00
|
|
|
echo '${
|
|
|
|
builtins.toJSON conf
|
|
|
|
}' | ${pkgs.buildPackages.jq}/bin/jq 'del(._module)' > $out
|
|
|
|
'';
|
2023-09-12 08:44:05 -06:00
|
|
|
in
|
|
|
|
{
|
2023-08-17 15:43:16 -06:00
|
|
|
options = with lib; {
|
|
|
|
services.rtlamr2mqtt = {
|
|
|
|
enable = mkEnableOption "Enable rtlamr2mqtt";
|
|
|
|
|
|
|
|
user = mkOption {
|
2023-09-12 08:44:05 -06:00
|
|
|
type = with types; oneOf [ str int ];
|
2023-08-17 15:43:16 -06:00
|
|
|
default = "rtlamr2mqtt";
|
|
|
|
description = ''
|
|
|
|
The user the service will use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
2023-09-12 08:44:05 -06:00
|
|
|
type = with types; oneOf [ str int ];
|
2023-08-17 15:43:16 -06:00
|
|
|
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 {
|
2023-09-12 08:44:05 -06:00
|
|
|
users.groups.rtlamr2mqtt = { };
|
2023-08-17 15:43:16 -06:00
|
|
|
users.users.rtlamr2mqtt = {
|
|
|
|
description = "rtlamr2mqtt service user";
|
|
|
|
isSystemUser = true;
|
|
|
|
home = "/var/lib/rtlamr2mqtt";
|
|
|
|
createHome = true;
|
|
|
|
group = "rtlamr2mqtt";
|
2023-09-12 08:44:05 -06:00
|
|
|
extraGroups = [ "plugdev" ];
|
2023-08-17 15:43:16 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.rtlamr2mqtt = {
|
|
|
|
enable = true;
|
|
|
|
description = "rtlamr2mqtt server";
|
2023-09-12 08:44:05 -06:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2023-08-17 15:43:16 -06:00
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
|
2023-09-06 07:29:03 -06:00
|
|
|
RuntimeDirectory = "rtlamr2mqtt";
|
2023-08-17 15:43:16 -06:00
|
|
|
|
|
|
|
ExecStart = "${cfg.package}/bin/rtlamr2mqtt ${prettyJSON cfg.configuration}";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|