Files
nixpkgs/pkgs/servers/home-assistant/default.nix

541 lines
16 KiB
Nix

{
stdenv,
lib,
callPackage,
fetchFromGitHub,
fetchPypi,
python314Packages,
replaceVars,
ffmpeg-headless,
inetutils,
nixosTests,
home-assistant,
versionCheckHook,
# Look up dependencies of specified components in component-packages.nix
extraComponents ? [ ],
# Additional packages to add to propagatedBuildInputs
extraPackages ? ps: [ ],
# Override Python packages using
# self: super: { pkg = super.pkg.overridePythonAttrs (oldAttrs: { ... }); }
# Applied after defaultOverrides
packageOverrides ? self: super: { },
# Skip pip install of required packages on startup
skipPip ? true,
}:
let
defaultOverrides = [
# Override the version of some packages pinned in Home Assistant's setup.py and requirements_all.txt
(self: super: {
aionotion = super.aionotion.overridePythonAttrs rec {
version = "2024.03.0";
src = fetchFromGitHub {
owner = "bachya";
repo = "aionotion";
tag = version;
hash = "sha256-BsbfLb5wCVxR8v2U2Zzt7LMl7XJcZWfVjZN47VDkhFc=";
};
postPatch = null;
};
aioskybell = super.aioskybell.overridePythonAttrs (oldAttrs: rec {
version = "22.7.0";
src = fetchFromGitHub {
owner = "tkdrob";
repo = "aioskybell";
tag = version;
hash = "sha256-aBT1fDFtq1vasTvCnAXKV2vmZ6LBLZqRCiepv1HDJ+Q=";
};
});
aiowatttime = super.aiowatttime.overridePythonAttrs (oldAttrs: rec {
version = "0.1.1";
src = fetchFromGitHub {
owner = "bachya";
repo = "aiowatttime";
tag = version;
hash = "sha256-tWnxGLJT+CRFvkhxFamHxnLXBvoR8tfOvzH1o1i5JJg=";
};
postPatch = ''
substituteInPlace pyproject.toml --replace-fail \
'"setuptools >= 35.0.2", "wheel >= 0.29.0", "poetry>=0.12"' \
'"poetry-core"'
'';
});
astral = super.astral.overridePythonAttrs (oldAttrs: rec {
pname = "astral";
version = "2.2";
src = fetchPypi {
inherit pname version;
hash = "sha256-5B2ZZ9XEi+QhNGVS8PTe2tQ/85qDV09f8q0ytmJ7b74=";
};
postPatch = ''
substituteInPlace pyproject.toml \
--replace-fail "poetry>=1.0.0b1" "poetry-core" \
--replace-fail "poetry.masonry" "poetry.core.masonry"
'';
propagatedBuildInputs = (oldAttrs.propagatedBuildInputs or [ ]) ++ [
self.pytz
];
});
caldav = self.caldav_2;
gspread = super.gspread.overridePythonAttrs (oldAttrs: rec {
version = "5.12.4";
src = fetchFromGitHub {
owner = "burnash";
repo = "gspread";
tag = "v${version}";
hash = "sha256-i+QbnF0Y/kUMvt91Wzb8wseO/1rZn9xzeA5BWg1haks=";
};
dependencies = with self; [
requests
];
});
livisi = super.livisi.overridePythonAttrs (oldAttrs: rec {
version = "0.0.25";
src = fetchFromGitHub {
owner = "planbnet";
repo = "livisi";
tag = "v${version}";
hash = "sha256-kEkbuZmYzxhrbTdo7eZJYu2N2uJtfspgqepplXvSXFg=";
};
});
notifications-android-tv = super.notifications-android-tv.overridePythonAttrs (oldAttrs: rec {
version = "0.1.5";
format = "setuptools";
pyproject = null;
src = fetchFromGitHub {
owner = "engrbm87";
repo = "notifications_android_tv";
tag = version;
hash = "sha256-adkcUuPl0jdJjkBINCTW4Kmc16C/HzL+jaRZB/Qr09A=";
};
nativeBuildInputs = with self; [
setuptools
];
propagatedBuildInputs = with self; [
requests
];
doCheck = false; # no tests
});
openhomedevice = super.openhomedevice.overridePythonAttrs (oldAttrs: rec {
version = "2.2";
src = fetchFromGitHub {
inherit (oldAttrs.src) owner repo;
tag = version;
hash = "sha256-GGp7nKFH01m1KW6yMkKlAdd26bDi8JDWva6OQ0CWMIw=";
};
});
plexapi = super.plexapi.overrideAttrs (oldAttrs: rec {
version = "4.15.16";
src = fetchFromGitHub {
owner = "pkkid";
repo = "python-plexapi";
tag = version;
hash = "sha256-NwGGNN6LC3gvE8zoVL5meNWMbqZjJ+6PcU2ebJTfJmU=";
};
# ancient pinned version requires pkg_resources
nativeBuildInputs = oldAttrs.nativeBuildInputs ++ [
self.setuptools_80
];
});
# Pinned due to API changes in 0.1.0
poolsense = super.poolsense.overridePythonAttrs (oldAttrs: rec {
version = "0.0.8";
src = fetchPypi {
pname = "poolsense";
inherit version;
hash = "sha256-17MHrYRmqkH+1QLtgq2d6zaRtqvb9ju9dvPt9gB2xCc=";
};
});
py-madvr2 = super.py-madvr2.overridePythonAttrs (oldAttrs: rec {
version = "1.6.40";
src = fetchFromGitHub {
owner = "iloveicedgreentea";
repo = "py-madvr";
tag = "v${version}";
hash = "sha256-0IX57Sa/oXGiViD39FVBRa2jxuKuZ3UNsOTHwuBdmWs=";
};
pythonImportsCheck = [ "madvr" ];
disabledTests = oldAttrs.disabledTests ++ [
"test_async_add_tasks"
"test_send_heartbeat"
];
});
# Pinned due to API changes >0.3.5.3
pyatag = super.pyatag.overridePythonAttrs (oldAttrs: rec {
version = "0.3.5.3";
src = fetchFromGitHub {
owner = "MatsNl";
repo = "pyatag";
rev = version;
sha256 = "00ly4injmgrj34p0lyx7cz2crgnfcijmzc0540gf7hpwha0marf6";
};
});
pyflume = super.pyflume.overridePythonAttrs (oldAttrs: rec {
version = "0.6.5";
src = fetchFromGitHub {
owner = "ChrisMandich";
repo = "PyFlume";
tag = "v${version}";
hash = "sha256-kIE3y/qlsO9Y1MjEQcX0pfaBeIzCCHk4f1Xa215BBHo=";
};
dependencies = oldAttrs.propagatedBuildInputs or [ ] ++ [
self.pytz
];
});
pysnooz = super.pysnooz.overridePythonAttrs (oldAttrs: rec {
version = "0.8.6";
src = fetchFromGitHub {
owner = "AustinBrunkhorst";
repo = "pysnooz";
tag = "v${version}";
hash = "sha256-hJwIObiuFEAVhgZXYB9VCeAlewBBnk0oMkP83MUCpyU=";
};
patches = [ ];
doCheck = false;
});
pytradfri = super.pytradfri.overridePythonAttrs (oldAttrs: rec {
version = "9.0.1";
src = fetchFromGitHub {
owner = "home-assistant-libs";
repo = "pytradfri";
tag = version;
hash = "sha256-xOdTzG0bF5p1QpkXv2btwrVugQRjSwdAj8bXcC0IoQg=";
};
patches = [ ];
doCheck = false;
});
serialx = super.serialx.overridePythonAttrs (oldAttrs: {
# many components use the serialx[esphome] implicitly
dependencies = oldAttrs.dependencies or [ ] ++ oldAttrs.optional-dependencies.esphome;
disabledTests = oldAttrs.disabledTests or [ ] ++ [
# network access, only runs with esphome extra
"test_connect_timeout_raises_timeout_error"
];
});
# internal python packages only consumed by home-assistant itself
hass-web-proxy-lib = self.callPackage ./python-modules/hass-web-proxy-lib { };
home-assistant-frontend = self.callPackage ./frontend.nix { };
home-assistant-intents = self.callPackage ./intents.nix { };
homeassistant = self.toPythonModule home-assistant;
pytest-homeassistant-custom-component =
self.callPackage ./pytest-homeassistant-custom-component.nix
{ };
})
];
python3Packages = python314Packages.overrideScope (
final: prev: lib.composeManyExtensions (defaultOverrides ++ [ packageOverrides ]) final prev
);
componentPackages = import ./component-packages.nix;
availableComponents = builtins.attrNames componentPackages.components;
inherit (componentPackages) supportedComponentsWithTests;
getPackages = component: componentPackages.components.${component};
componentBuildInputs = lib.concatMap (
component: getPackages component python3Packages
) extraComponents;
# Ensure that we are using a consistent package set
extraBuildInputs = extraPackages python3Packages;
# Don't forget to run update-component-packages.py after updating
hassVersion = "2026.8.2";
in
python3Packages.buildPythonApplication rec {
pname = "homeassistant";
version =
assert (componentPackages.version == hassVersion);
hassVersion;
pyproject = true;
# check REQUIRED_PYTHON_VER in homeassistant/const.py
disabled = python3Packages.pythonOlder "3.14";
# don't try and fail to strip 6600+ python files, it takes minutes!
dontStrip = true;
# Primary source is the git, which has the tests and allows bisecting the core
src = fetchFromGitHub {
owner = "home-assistant";
repo = "core";
tag = version;
hash = "sha256-u8vXAsO1jQpUpvqSRuYMOR8eY0Oqk7T4A/aRneE88Qg=";
};
# Secondary source is pypi sdist for translations
sdist = fetchPypi {
inherit pname version;
hash = "sha256-ImLh7LxH/p08y2kPmfFxdp+vUgFyCLf/Zsnbv79w990=";
};
build-system = with python3Packages; [
setuptools
];
pythonRelaxDeps = true;
# extract translations from pypi sdist
prePatch = ''
tar --extract --gzip --file $sdist --strip-components 1 --wildcards "**/translations"
'';
# leave this in, so users don't have to constantly update their downstream patch handling
patches = [
# Follow symlinks in /var/lib/hass/www
./patches/static-follow-symlinks.patch
# Copy default blueprints without preserving permissions
./patches/default-blueprint-permissions.patch
# No scaring our users about not running in a docker or a venv
./patches/pythonpath-is-a-venv.patch
# No scaring our users about our install method
./patches/nixos-was-never-supported.patch
# Patch path to ffmpeg binary
(replaceVars ./patches/ffmpeg-path.patch {
ffmpeg = "${lib.getExe ffmpeg-headless}";
})
];
postPatch = ''
substituteInPlace tests/test_core_config.py --replace-fail '"/usr"' "\"$NIX_BUILD_TOP/media\""
substituteInPlace pyproject.toml \
--replace-fail "setuptools==78.1.1" setuptools
# https://github.com/RenierM26/pyEzvizApi/commit/ae0651ea93f031e94e7286fa3439fcc12acfb001
substituteInPlace homeassistant/components/ezviz/switch.py \
--replace-fail "SupportFulldayRecord" "SupportFullDayRecord"
'';
pythonRemoveDeps = [
"uv"
];
dependencies = with python3Packages; [
# Mirror what gets installed for Home Assistant Container, which means
# installing what is in requirements.txt. The PEP517 specification gets
# embedded in wheel metadata but only represents a subset.
# Proof: https://github.com/home-assistant/core/blob/2026.5.0/Dockerfile#L40
aiodns
aiogithubapi
aiohasupervisor
aiohttp
aiohttp-asyncmdnsresolver
aiohttp-cors
aiohttp-fast-zlib
aiozoneinfo
annotatedyaml
astral
async-interrupt
atomicwrites-homeassistant
attrs
audioop-lts
awesomeversion
bcrypt
certifi
ciso8601
cronsim
cryptography
fnv-hash-fast
ha-ffmpeg
hass-nabucasa
hassil
home-assistant-bluetooth
home-assistant-intents
httpx
ifaddr
infrared-protocols
jinja2
lru-dict
mutagen
orjson
packaging
pillow
propcache
psutil-home-assistant
pyjwt
pymicro-vad
pyopenssl
pyspeex-noise
python-slugify
pyturbojpeg
pyyaml
requests
rf-protocols
securetar
sqlalchemy
standard-aifc
standard-telnetlib
typing-extensions
ulid-transform
urllib3
voluptuous
voluptuous-openapi
voluptuous-serialize
webrtc-models
yarl
zeroconf
# REQUIREMENTS in homeassistant/auth/mfa_modules/totp.py and homeassistant/auth/mfa_modules/notify.py
pyotp
pyqrcode
];
makeWrapperArgs = lib.optional skipPip "--add-flags --skip-pip";
# upstream only tests on Linux, so do we.
doCheck = stdenv.hostPlatform.isLinux;
requirementsTest = with python3Packages; [
# test infrastructure (selectively from requirement_test.txt)
freezegun
pytest-asyncio
pytest-aiohttp
pytest-freezer
pytest-socket
pytest-timeout
pytest-unordered
pytest-xdist
pytestCheckHook
requests-mock
respx
syrupy
unidiff
# Used in tests/common.py
paho-mqtt
];
nativeCheckInputs =
requirementsTest
++ [ versionCheckHook ]
++ (with python3Packages; [
# Used in tests/non_packaged_scripts/test_alexa_locales.py
beautifulsoup4
# Used in tests/scripts/test_check_config.py
colorlog
# Used in tests/helpers/test_httpx_client.py
h2
# Used in tests/mypy_plugins/test_enum_identity_compare.py
mypy
# Used in tests/scripts/check_requirements/test_gate.py
pygithub
])
++ lib.concatMap (component: getPackages component python3Packages) [
# some components are needed even if tests in tests/components are disabled
"frontend"
"hue"
];
pytestFlags = [
# assign tests grouped by file to workers
"--dist=loadfile"
# enable full variable printing on error
"--showlocals"
];
enabledTestPaths = [
# tests are located in tests/
"tests"
];
disabledTestPaths = [
# we neither run nor distribute hassfest
"tests/hassfest"
# we don't care about code quality
"tests/pylint"
# redundant component import test, which would make debugpy & sentry expensive to review
"tests/test_circular_imports.py"
# don't bulk test all components
"tests/components"
# AssertionError: assert 1 == 0
"tests/test_config.py::test_merge"
# checks whether pip is installed
"tests/util/test_package.py::test_check_package_fragment"
# flaky
"tests/test_bootstrap.py::test_setup_hass_takes_longer_than_log_slow_startup"
"tests/test_test_fixtures.py::test_evict_faked_translations"
"tests/helpers/test_backup.py::test_async_get_manager"
"tests/helpers/test_trigger.py::test_platform_multiple_triggers[sync_action]"
# various failing after python-updates
"tests/helpers/test_entity_platform.py::test_platform_warn_slow_setup" # ValueError: not enough values to unpack (expected 2, got 0)
"tests/helpers/test_entity_component.py::test_set_scan_interval_via_config" # assert 10 == 30.0
"tests/helpers/test_entity_component.py::test_set_entity_namespace_via_config" # AssertionError: assert [] == ['test_domain...named_device']
];
preCheck = ''
export HOME="$TEMPDIR"
export PYTHONASYNCIODEBUG=1
# the tests require the existence of a media dir
mkdir "$NIX_BUILD_TOP"/media
# put ping binary into PATH, e.g. for wake_on_lan tests
export PATH=${inetutils}/bin:$PATH
'';
passthru = {
inherit
availableComponents
extraComponents
getPackages
python3Packages
supportedComponentsWithTests
;
pythonPath = python3Packages.makePythonPath (componentBuildInputs ++ extraBuildInputs);
frontend = python3Packages.home-assistant-frontend;
intents = python3Packages.home-assistant-intents;
tests = {
nixos = nixosTests.home-assistant;
components = callPackage ./tests.nix { };
withoutCheckDeps = home-assistant.overridePythonAttrs {
pname = "home-assistant-without-check-deps";
doCheck = false;
};
};
};
meta = {
homepage = "https://home-assistant.io/";
changelog = "https://github.com/home-assistant/core/releases/tag/${src.tag}";
description = "Open source home automation that puts local control and privacy first";
license = lib.licenses.asl20;
teams = [ lib.teams.home-assistant ];
platforms = lib.platforms.linux;
mainProgram = "hass";
};
}