self: { config, pkgs, lib, system, ... }: let cfg = config.programs.oh-importer; appConfig = (pkgs.formats.yaml {}).generate "oh-importer.config.yaml" cfg.config; app = pkgs.writeShellApplication { name = "oh-import"; runtimeInputs = [self.packages.${system}.default]; text = '' oh-import -c "${appConfig}" "$@"; ''; }; in with lib; { options.programs.oh-importer = { enable = mkEnableOption "oh-importer"; config = mkOption { type = types.attrs; description = "The oh-importer config which will be eventually converted to yaml"; example = { openHAB = { baseURL = "https://hab.lan"; token = "$__file:/run/openhab.token.key"; }; sources = { zigbee = { type = "zigbee2mqtt"; config = { brokerURL = "mqtt://mqtt.lan"; username = "mqtt-username"; password = "$__file:/run/mqtt.password.key"; bridgeID = "main"; prefix = "zigbee"; idTransform = "snake-case"; }; }; }; }; }; }; config.environment.systemPackages = mkIf cfg.enable [app]; }