Repository navigation
Description
Nixpkgs version
- Unstable (26.05)
Describe the bug
When services.esphome is enabled and configured, the dashboard commands fail with no such module found.
I managed to solve it by adding
PYTHONPATH = "${pkgs.esphome}/lib/python3.13/site-packages:${pkgs.python3Packages.makePythonPath pkgs.esphome.dependencies}";
to the service's environment
Once that is solved however, the current systemd service with its hardening settings creates several permissions issues when building yaml files. Here is the overrides I'm using which creates a dedicated user and creates an option to specify a custom state directory. Perhaps it can be merged upstream
{
config,
lib,
pkgs,
...
}:
let
inherit (lib)
maintainers
mkIf
mkOption
types
;
cfg = config.services.esphome;
esphomeParams =
if cfg.enableUnixSocket then
"--socket /run/esphome/esphome.sock"
else
"--address ${cfg.address} --port ${toString cfg.port}";
in
{
meta.maintainers = with maintainers; [ oddlama ];
options.services.esphome = {
user = mkOption {
type = types.str;
default = "esphome";
description = "User account under which esphome runs.";
};
group = mkOption {
type = types.str;
default = "esphome";
description = "Group under which esphome runs.";
};
stateDir = mkOption {
type = types.path;
default = "/var/lib/esphome";
description = "the folder used to store all esphome data.";
};
};
config = mkIf cfg.enable {
users = {
users = mkIf (cfg.user == "esphome") {
esphome = {
inherit (cfg) group;
isSystemUser = true;
};
};
groups = mkIf (cfg.group == "esphome") { esphome = { }; };
};
systemd.tmpfiles.rules = [
"d ${cfg.stateDir} 0750 ${cfg.user} ${cfg.group} -"
];
systemd.services.esphome = {
environment = {
# platformio fails to determine the home directory when using DynamicUser
PLATFORMIO_CORE_DIR = lib.mkForce "${cfg.stateDir}/.platformio";
PYTHONPATH = "${pkgs.esphome}/lib/python3.13/site-packages:${pkgs.python3Packages.makePythonPath pkgs.esphome.dependencies}";
};
serviceConfig = {
ExecStart = lib.mkForce "${cfg.package}/bin/esphome dashboard ${esphomeParams} ${cfg.stateDir}";
User = cfg.user;
Group = cfg.group;
DynamicUser = lib.mkForce false;
WorkingDirectory = lib.mkForce cfg.stateDir;
StateDirectory = lib.mkForce "";
StateDirectoryMode = lib.mkForce "";
ReadWritePaths = [ cfg.stateDir ];
};
};
};
}Steps to reproduce
add services.esphome.enabled = true to config
services.esphome = {
enable = true;
port = 6052;
};Go to the web dashboard at https://localhost:6052.
Try to add a device, clean files or perform any other action
Note the error.
Expected behaviour
Commands should work instead of returning module not found: esphome
Screenshots
No response
Relevant log output
Additional context
I managed to solve it by adding
systemd.services.esphome = {
environment = {
PYTHONPATH = "${pkgs.esphome}/lib/python3.13/site-packages:${pkgs.python3Packages.makePythonPath pkgs.esphome.dependencies}";
};
};System metadata
- system:
"x86_64-linux" - host os:
Linux 6.18.19, NixOS, 26.05 (Yarara), 26.05.20260324.46db2e0 - multi-user?:
yes - sandbox:
yes - version:
nix-env (Nix) 2.31.3 - nixpkgs:
/nix/store/fvb3fhm8c193i6692v5223bxpa5w2nv7-source
Notify maintainers
Note for maintainers: Please tag this issue in your pull request description. (i.e. Resolves #ISSUE.)
I assert that this issue is relevant for Nixpkgs
- I assert that this is a bug and not a support request.
- I assert that this is not a duplicate of an existing issue.
- I assert that I have read the NixOS Code of Conduct and agree to abide by it.
Is this issue important to you?
Add a 👍 reaction to issues you find important.
Activity