From 01616e5331d2790127aa2e61c126fff9467889f2 Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Sat, 25 Nov 2023 16:32:41 +0100 Subject: buildHomeAssistantComponent: migrate from pname to owner/domain Also make the attribute name to match the domain name. This is more in line with the home-assistant custom component ecosystem and allows additional validation between the derivation and the manifest. Also, at a later time, this will enable us to check for domain conflicts at eval time. --- .../home-assistant/custom-components/README.md | 30 +++++++++++++++++----- .../home-assistant/custom-components/default.nix | 2 +- .../prometheus-sensor/default.nix | 26 ------------------- .../prometheus_sensor/default.nix | 27 +++++++++++++++++++ 4 files changed, 51 insertions(+), 34 deletions(-) delete mode 100644 pkgs/servers/home-assistant/custom-components/prometheus-sensor/default.nix create mode 100644 pkgs/servers/home-assistant/custom-components/prometheus_sensor/default.nix (limited to 'pkgs/servers/home-assistant/custom-components') diff --git a/pkgs/servers/home-assistant/custom-components/README.md b/pkgs/servers/home-assistant/custom-components/README.md index a7244b25c173..d7137e5c62f7 100644 --- a/pkgs/servers/home-assistant/custom-components/README.md +++ b/pkgs/servers/home-assistant/custom-components/README.md @@ -25,7 +25,7 @@ versions into the Python environment. }: buildHomeAssistantComponent { - # pname, version + # owner, domain, version src = fetchFromGithub { # owner, repo, rev, hash @@ -40,18 +40,34 @@ buildHomeAssistantComponent { } } -## Package name normalization +## Package attribute -Apply the same normalization rules as defined for python packages in -[PEP503](https://peps.python.org/pep-0503/#normalized-names). -The name should be lowercased and dots, underlines or multiple -dashes should all be replaced by a single dash. +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`. + +Don't set `pname`, set `owner and `domain` instead. + +Exposing the `domain` attribute separately allows checking for +conflicting components at eval time. ## Manifest check The `buildHomeAssistantComponent` builder uses a hook to check whether the dependencies specified in the `manifest.json` are present and -inside the specified version range. +inside the specified version range. It also makes sure derivation +and manifest agree about the domain name. There shouldn't be a need to disable this hook, but you can set `dontCheckManifest` to `true` in the derivation to achieve that. diff --git a/pkgs/servers/home-assistant/custom-components/default.nix b/pkgs/servers/home-assistant/custom-components/default.nix index 4a96b305964a..15bd721c72e8 100644 --- a/pkgs/servers/home-assistant/custom-components/default.nix +++ b/pkgs/servers/home-assistant/custom-components/default.nix @@ -2,5 +2,5 @@ }: { - prometheus-sensor = callPackage ./prometheus-sensor {}; + prometheus_sensor = callPackage ./prometheus_sensor {}; } diff --git a/pkgs/servers/home-assistant/custom-components/prometheus-sensor/default.nix b/pkgs/servers/home-assistant/custom-components/prometheus-sensor/default.nix deleted file mode 100644 index 07bcd9abec1c..000000000000 --- a/pkgs/servers/home-assistant/custom-components/prometheus-sensor/default.nix +++ /dev/null @@ -1,26 +0,0 @@ -{ lib -, fetchFromGitHub -, buildHomeAssistantComponent -}: - -buildHomeAssistantComponent rec { - pname = "prometheus-sensor"; - version = "1.0.0"; - - src = fetchFromGitHub { - owner = "mweinelt"; - repo = "ha-prometheus-sensor"; - rev = "refs/tags/${version}"; - hash = "sha256-10COLFXvmpm8ONLyx5c0yiQdtuP0SC2NKq/ZYHro9II="; - }; - - dontBuild = true; - - meta = with lib; { - changelog = "https://github.com/mweinelt/ha-prometheus-sensor/blob/${version}/CHANGELOG.md"; - description = "Import prometheus query results into Home Assistant"; - homepage = "https://github.com/mweinelt/ha-prometheus-sensor"; - maintainers = with maintainers; [ hexa ]; - license = licenses.mit; - }; -} diff --git a/pkgs/servers/home-assistant/custom-components/prometheus_sensor/default.nix b/pkgs/servers/home-assistant/custom-components/prometheus_sensor/default.nix new file mode 100644 index 000000000000..2368d85552b2 --- /dev/null +++ b/pkgs/servers/home-assistant/custom-components/prometheus_sensor/default.nix @@ -0,0 +1,27 @@ +{ lib +, fetchFromGitHub +, buildHomeAssistantComponent +}: + +buildHomeAssistantComponent rec { + owner = "mweinelt"; + domain = "prometheus_sensor"; + version = "1.0.0"; + + src = fetchFromGitHub { + owner = "mweinelt"; + repo = "ha-prometheus-sensor"; + rev = "refs/tags/${version}"; + hash = "sha256-10COLFXvmpm8ONLyx5c0yiQdtuP0SC2NKq/ZYHro9II="; + }; + + dontBuild = true; + + meta = with lib; { + changelog = "https://github.com/mweinelt/ha-prometheus-sensor/blob/${version}/CHANGELOG.md"; + description = "Import prometheus query results into Home Assistant"; + homepage = "https://github.com/mweinelt/ha-prometheus-sensor"; + maintainers = with maintainers; [ hexa ]; + license = licenses.mit; + }; +} -- cgit 1.4.1