1
0
mirror of https://github.com/kmein/niveum synced 2026-03-16 18:21:07 +01:00
Files
niveum/modules/traadfri.nix

48 lines
1.2 KiB
Nix
Raw Normal View History

2022-03-10 21:52:12 +01:00
{
pkgs,
lib,
config,
2023-02-23 16:53:53 +01:00
inputs,
2022-03-10 21:52:12 +01:00
...
}:
with lib; let
2019-06-10 17:05:36 +02:00
cfg = config.niveum.traadfri;
2020-06-10 17:37:25 +02:00
in {
2019-06-10 17:05:36 +02:00
options.niveum.traadfri = {
enable = mkEnableOption "Trådfri CLI";
2022-03-10 21:52:12 +01:00
user = mkOption {type = types.str;};
host = mkOption {type = types.str;};
2023-02-23 16:53:53 +01:00
keyFile = mkOption {type = types.path;};
2020-06-10 17:37:25 +02:00
rooms = mkOption {
type = types.attrsOf types.int;
2022-03-10 21:52:12 +01:00
default = {};
2020-06-10 17:37:25 +02:00
};
bulbs = mkOption {
type = types.attrsOf types.int;
2022-03-10 21:52:12 +01:00
default = {};
2020-06-10 17:37:25 +02:00
};
2019-06-10 17:05:36 +02:00
};
config = mkIf cfg.enable {
2022-03-10 21:52:12 +01:00
environment.systemPackages =
[
(pkgs.writers.writeDashBin "traadfri" ''
2023-02-23 16:53:53 +01:00
export TRAADFRI_USER="${cfg.user}"
export TRAADFRI_KEY="$(cat ${lib.escapeShellArg cfg.keyFile})"
export TRAADFRI_HUB="${cfg.host}"
${inputs.traadfri.defaultPackage.x86_64-linux}/bin/traadfri $@
2022-03-10 21:52:12 +01:00
'')
]
++ lib.mapAttrsToList (name: value:
pkgs.writers.writeDashBin "traadfri-${name}" ''
exec traadfri --target Room ${toString value} "$@"
'')
cfg.rooms
++ lib.mapAttrsToList (name: value:
pkgs.writers.writeDashBin "traadfri-${name}" ''
exec traadfri --target Bulb ${toString value} "$@"
'')
cfg.bulbs;
2019-06-10 17:05:36 +02:00
};
}