49 lines
1.1 KiB
Nix
49 lines
1.1 KiB
Nix
|
{ config, lib, pkgs, ... }:
|
||
|
|
||
|
with lib;
|
||
|
|
||
|
let
|
||
|
|
||
|
cfg = config.services.mqtt.light-control;
|
||
|
|
||
|
mkMagicMergeOption = { description ? "", example ? { }, default ? { }, ... }:
|
||
|
mkOption {
|
||
|
inherit example description default;
|
||
|
type = with lib.types;
|
||
|
let
|
||
|
valueType = nullOr (oneOf [
|
||
|
bool
|
||
|
int
|
||
|
float
|
||
|
str
|
||
|
(attrsOf valueType)
|
||
|
(listOf valueType)
|
||
|
]) // {
|
||
|
description = "";
|
||
|
emptyValue.value = { };
|
||
|
};
|
||
|
in valueType;
|
||
|
};
|
||
|
|
||
|
lightControlConfig =
|
||
|
pkgs.writeText "light-control.json" (builtins.toJSON cfg.config);
|
||
|
|
||
|
in {
|
||
|
|
||
|
options.services.mqtt.light-control = {
|
||
|
enable = mkEnableOption "enable mqtt.light-control";
|
||
|
config =
|
||
|
mkMagicMergeOption { description = "configuration of light-control"; };
|
||
|
};
|
||
|
|
||
|
config = mkIf cfg.enable {
|
||
|
systemd.services."light-control" = {
|
||
|
wantedBy = [ "multi-user.target" ];
|
||
|
environment = { RUST_LOG = "rust_iot=trace"; };
|
||
|
script = ''
|
||
|
${pkgs.light-control}/bin/rust-iot ${lightControlConfig}
|
||
|
'';
|
||
|
};
|
||
|
};
|
||
|
}
|