2023-11-16 04:20:00 +00:00
# Packaging guidelines
## buildHomeAssistantComponent
Custom components should be packaged using the
`buildHomeAssistantComponent` function, that is provided at top-level.
It builds upon `buildPythonPackage` but uses a custom install and check
phase.
Python runtime dependencies can be directly consumed as unqualified
function arguments. Pass them into `propagatedBuildInputs` , for them to
be available to Home Assistant.
2024-04-21 15:54:59 +00:00
Out-of-tree components need to use Python packages from
2023-11-16 04:20:00 +00:00
`home-assistant.python.pkgs` as to not introduce conflicting package
versions into the Python environment.
**Example Boilerplate:**
```nix
{ lib
2024-07-27 06:49:29 +00:00
, buildHomeAssistantComponent
2023-11-16 04:20:00 +00:00
, fetchFromGitHub
}:
buildHomeAssistantComponent {
2024-01-02 11:29:13 +00:00
# owner, domain, version
2023-11-16 04:20:00 +00:00
src = fetchFromGithub {
# owner, repo, rev, hash
};
propagatedBuildInputs = [
# python requirements, as specified in manifest.json
];
meta = with lib; {
# changelog, description, homepage, license, maintainers
2024-04-21 15:54:59 +00:00
};
2023-11-16 04:20:00 +00:00
}
2024-01-13 08:15:51 +00:00
```
2023-11-16 04:20:00 +00:00
2024-01-02 11:29:13 +00:00
## Package attribute
2023-11-16 04:20:00 +00:00
2024-01-02 11:29:13 +00:00
The attribute name must reflect the domain as seen in the
`manifest.json` , which in turn will match the python module name below
in the `custom_components/` directory.
**Example:**
The project [mweinelt/ha-prometheus-sensor ](https://github.com/mweinelt/ha-prometheus-sensor/blob/1.0.0/custom_components/prometheus_sensor/manifest.json#L2 )
would receive the attribute name `"prometheus_sensor"` , because both
domain in the `manifest.json` as well as the module name are
`prometheus_sensor` .
## Package name
The `pname` attribute is a composition of both `owner` and `domain` .
2024-04-21 15:54:59 +00:00
Don't set `pname` , set `owner` and `domain` instead.
2024-01-02 11:29:13 +00:00
Exposing the `domain` attribute separately allows checking for
conflicting components at eval time.
2023-11-16 04:20:00 +00:00
## Manifest check
The `buildHomeAssistantComponent` builder uses a hook to check whether
the dependencies specified in the `manifest.json` are present and
2024-01-02 11:29:13 +00:00
inside the specified version range. It also makes sure derivation
and manifest agree about the domain name.
2023-11-16 04:20:00 +00:00
There shouldn't be a need to disable this hook, but you can set
`dontCheckManifest` to `true` in the derivation to achieve that.