This commit is contained in:
mjallen18
2026-03-16 17:20:16 -05:00
parent ad348a0f9e
commit 9ad581f0e5
4 changed files with 12 additions and 102 deletions

View File

@@ -1,45 +1,28 @@
{
config,
lib,
pkgs,
namespace,
...
}:
with lib;
let
cfg = config.${namespace}.services.home-assistant;
# ESPHome with littlefs-python and fatfs-ng added to PYTHONPATH so PlatformIO's
# espressif32 platform builder can import them (needed for LittleFS/FAT support).
# fatfs-ng is the correct package: it installs under the 'fatfs' namespace and
# provides create_extended_partition and ESP32 wear-leveling support required by
# pioarduino's platform builder (penv_setup.py specifies "fatfs-ng>=0.1.14").
esphomeWithLittlefs = pkgs.esphome.overridePythonAttrs (oldAttrs: {
makeWrapperArgs = (oldAttrs.makeWrapperArgs or [ ]) ++ [
"--prefix PYTHONPATH : ${pkgs.${namespace}.littlefs-python}/${pkgs.python3.sitePackages}"
"--prefix PYTHONPATH : ${pkgs.${namespace}.fatfs-ng}/${pkgs.python3.sitePackages}"
];
});
in
{
config = mkIf cfg.enable {
services = {
esphome = {
enable = true;
openFirewall = true; # 6052
address = "0.0.0.0";
package = esphomeWithLittlefs;
virtualisation.oci-containers.containers.esphome = {
autoStart = true;
image = "ghcr.io/esphome/esphome:2026.2.4";
ports = [ "6052:6052" ];
volumes = [
"/var/lib/esphome:/config"
];
environment = {
TZ = "America/Chicago";
};
};
# Add uv to the ESPHome service PATH so PlatformIO uses the Nix-provided
# binary instead of downloading its own (which would fail due to permissions).
# Also disable MemoryDenyWriteExecute so uv (a native Rust binary) can run.
systemd.services.esphome = {
path = [ pkgs.uv ];
serviceConfig = {
MemoryDenyWriteExecute = lib.mkForce false;
};
};
# Open the ESPHome dashboard port
networking.firewall.allowedTCPPorts = [ 6052 ];
};
}