Create NixOS module

This commit is contained in:
2024-11-16 15:16:29 +01:00
parent d167ced2bf
commit c82234710f
2 changed files with 58 additions and 1 deletions

View File

@@ -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
View 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];
}