diff --git a/flake.nix b/flake.nix index f5df452..96a7477 100644 --- a/flake.nix +++ b/flake.nix @@ -19,5 +19,11 @@ oh-importer = pkgs.callPackage ./package.nix {}; default = oh-importer; }; - }); + }) + // { + nixosModules = rec { + oh-importer = import ./module.nix self; + default = oh-importer; + }; + }; } diff --git a/module.nix b/module.nix new file mode 100644 index 0000000..f275509 --- /dev/null +++ b/module.nix @@ -0,0 +1,51 @@ +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]; + }