home-assistant: add support for declarative blueprints

This commit is contained in:
Sandro - 2024-02-16 00:21:00 +01:00
parent 043ea48acb
commit 4c107d51a6
Signed by: sandro
GPG Key ID: 3AF5A43A3EECC2E5
1 changed files with 39 additions and 0 deletions

View File

@ -7,6 +7,26 @@ in
{
options = {
services.home-assistant = {
blueprints = lib.mkOption {
type = with lib.types; listOf package;
default = [];
example = lib.literalExpression ''
[
(pkgs.fetchFromGitHub {
owner = "...";
repo = "...";
rev = "...";
hash = "...";
passthru = {
path = "../...yaml";
domain = "automation"; # or script
author = "...";
};
})
]
'';
};
ldap = {
enable = lib.mkEnableOption (lib.mdDoc ''login only via LDAP
@ -139,6 +159,25 @@ in
permissions = { };
};
config.systemd.services = lib.mkIf (cfg.enable && cfg.blueprints != []) {
# copied and adopted from customComponents
home-assistant.preStart = ''
mkdir -p "${cfg.configDir}/blueprints"
# remove components symlinked in from below the /nix/store
readarray -d "" blueprint < <(find "${cfg.configDir}/blueprints" -maxdepth 1 -type l -print0)
for blueprint in "''${blueprint[@]}"; do
if [[ "$(readlink "$blueprint")" =~ ^${lib.escapeShellArg builtins.storeDir} ]]; then
rm "$blueprint"
fi
done
# recreate symlinks for desired blueprints
'' + lib.concatMapStringsSep "\n" (blueprint: ''
ln -fns "${blueprint}/${blueprint.passthru.path}" "${cfg.configDir}/blueprints/${blueprint.passthru.domain}/${blueprint.passthru.author}/"
'') cfg.blueprints;
};
config.systemd.tmpfiles.rules = lib.mkIf (cfg.enable && cfg.recommendedDefaults) [
"f ${cfg.configDir}/automations.yaml 0444 hass hass"
];