nixos-config/nixos/modules/services/light-control.nix

56 lines
1.3 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";
loglevel = mkOption {
default = "info";
type = with types; enum [ "info" "trace" "debug" "error" "warning" ];
};
config =
mkMagicMergeOption { description = "configuration of light-control"; };
};
config = mkIf cfg.enable {
systemd.services."light-control" = {
wantedBy = [ "multi-user.target" ];
environment = { RUST_LOG = "light_control=${cfg.loglevel}"; };
script = ''
${pkgs.light-control}/bin/light-control ${lightControlConfig}
'';
};
};
}