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

53 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
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";
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
'';
};
};
}