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

56 lines
1.3 KiB
Nix
Raw Normal View History

2020-06-01 14:34:23 +02:00
{ 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
2021-11-01 09:20:42 +01:00
valueType = nullOr
(oneOf [
bool
int
float
str
(attrsOf valueType)
(listOf valueType)
]) // {
2020-06-01 14:34:23 +02:00
description = "";
emptyValue.value = { };
};
2021-11-01 09:20:42 +01:00
in
valueType;
2020-06-01 14:34:23 +02:00
};
lightControlConfig =
pkgs.writeText "light-control.json" (builtins.toJSON cfg.config);
2021-11-01 09:20:42 +01:00
in
{
2020-06-01 14:34:23 +02:00
options.services.mqtt.light-control = {
enable = mkEnableOption "enable mqtt.light-control";
2020-06-04 01:44:50 +02:00
loglevel = mkOption {
default = "info";
type = with types; enum [ "info" "trace" "debug" "error" "warning" ];
};
2020-06-01 14:34:23 +02:00
config =
mkMagicMergeOption { description = "configuration of light-control"; };
};
config = mkIf cfg.enable {
systemd.services."light-control" = {
wantedBy = [ "multi-user.target" ];
2020-06-04 01:44:50 +02:00
environment = { RUST_LOG = "light_control=${cfg.loglevel}"; };
2020-06-01 14:34:23 +02:00
script = ''
${pkgs.light-control}/bin/light-control ${lightControlConfig}
2020-06-01 14:34:23 +02:00
'';
};
};
}