Create NixOS module
This commit is contained in:
@@ -19,5 +19,11 @@
|
|||||||
oh-importer = pkgs.callPackage ./package.nix {};
|
oh-importer = pkgs.callPackage ./package.nix {};
|
||||||
default = oh-importer;
|
default = oh-importer;
|
||||||
};
|
};
|
||||||
});
|
})
|
||||||
|
// {
|
||||||
|
nixosModules = rec {
|
||||||
|
oh-importer = import ./module.nix self;
|
||||||
|
default = oh-importer;
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
51
module.nix
Normal file
51
module.nix
Normal file
@@ -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];
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user