Skip to content

nixos/esphome: replace DynamicUser with static system user - #508178

Merged
tomfitzhenry merged 1 commit into
NixOS:masterfrom
JamieMagee:esphome/nixos-static-user
Apr 11, 2026
Merged

tomfitzhenry merged 1 commit into
NixOS:masterfrom
JamieMagee:esphome/nixos-static-user

Conversation

@JamieMagee

@JamieMagee JamieMagee commented Apr 9, 2026 •

Copy link
Copy Markdown
Member

DynamicUser symlinks /var/lib/esphome to /var/lib/private/esphome. PlatformIO can't resolve paths through the symlink, so firmware compilation fails with permission errors or duplicate target errors.

This switches to a static esphome system user and group, same pattern as zigbee2mqtt and other stateful services. PLATFORMIO_CORE_DIR and HOME now point to real paths.

Hardening options that were previously implied by DynamicUser (NoNewPrivileges, PrivateTmp, RemoveIPC, RestrictSUIDSGID) are now set explicitly.

One thing I'm not sure how to handle: users with existing data in /var/lib/private/esphome will need to move it to /var/lib/esphome and chown to esphome:esphome.

Fixes #339557

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

@nixpkgs-ci
nixpkgs-ci Bot requested a review from oddlama April 9, 2026 04:52
@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Apr 9, 2026
@JamieMagee

Copy link
Copy Markdown
Member Author

nixpkgs-review result

Generated using nixpkgs-review-gha

Command: nixpkgs-review pr 508178
Commit: c9deb509b0eafb65370d54f37993ef3af155e882 (subsequent changes)
Merge: d5d7cec8bb58811689bf3d81d91ba837937cc037

Logs: https://github.com/JamieMagee/nixpkgs-review-gha/actions/runs/24173142310


x86_64-linux

⏩ 2 packages blacklisted:
  • nixos-install-tools
  • tests.nixos-functions.nixos-test

aarch64-linux

⏩ 2 packages blacklisted:
  • nixos-install-tools
  • tests.nixos-functions.nixos-test

@tomfitzhenry tomfitzhenry left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I'm not sure how to handle: users with existing data in /var/lib/private/esphome will need to move it to /var/lib/esphome and chown to esphome:esphome.

Since it's a breaking change, this at least needs a mention in the release notes.

It's a shame to lose DynamicUser, and also introduce a breaking change, especially since the upstream fix might be easy if only the developers know. Is it worth raising an issue at https://github.com/esphome/esphome ?

@azban

azban commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

This seems related enough to consider when reviewing: #486701

@SuperSandro2000

SuperSandro2000 commented Apr 11, 2026 •

Copy link
Copy Markdown
Member

One thing I'm not sure how to handle: users with existing data in /var/lib/private/esphome will need to move it to /var/lib/esphome and chown to esphome:esphome.

Since it's a breaking change, this at least needs a mention in the release notes.

It isn't really a breaking change. I disabled DynamicUser and systemd does everything for you:

Apr 11 04:50:21 esphome systemd[1]: Started ESPHome dashboard.
Apr 11 04:50:21 esphome (esphome)[1916]: esphome.service: Found pre-existing private StateDirectory= directory /var/lib/private/esphome, migrating to /var/lib/esphome.
Apr 11 04:50:21 esphome (esphome)[1916]: esphome.service: Apparently, service previously had DynamicUser= turned on, and has now turned it off.

It's a shame to lose DynamicUser

No, it really isn't. We are easily storing a few 100 MBs of cached data in many files, the existing socket option works poor with DynamicUser and it causes permission errors and all of that for very little benefit.

especially since the upstream fix might be easy if only the developers know. Is it worth raising an issue at esphome/esphome ?

I do not think fixing that is easy. It might need fixes in esphome and platformio and maybe also some third component and they will likely tell you to use their esphome docker image or the home assistant addon.

@SuperSandro2000

Copy link
Copy Markdown
Member

And the compile cache currently gets invalidated with every run. I would not be surprised by all means if DynamicUser caused that somehow, but I did not investigate that at all.

@nixpkgs-ci nixpkgs-ci Bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Apr 11, 2026
@nixpkgs-ci nixpkgs-ci Bot added 12.approvals: 2 This PR was reviewed and approved by two persons. and removed 12.approvals: 1 This PR was reviewed and approved by one person. labels Apr 11, 2026
@oddlama

oddlama commented Apr 11, 2026

Copy link
Copy Markdown
Member

Since it's a breaking change, this at least needs a mention in the release notes.

It isn't really a breaking change. I disabled DynamicUser and systemd does everything for you:

Might be breaking for people using impermanence. Systemd will migrate the data from a persistent directory into a non persisted directory which effectively deletes the files on next reboot.

Now arguably impermanence isnt NixOS core stuff, but it might affect enough users to warrant a release note entry.

DynamicUser symlinks /var/lib/esphome to /var/lib/private/esphome,
which breaks PlatformIO path resolution during compilation.

Use a static system user instead. Also set PLATFORMIO_CORE_DIR and
HOME to real paths, and enable NoNewPrivileges, PrivateTmp, RemoveIPC,
RestrictSUIDSGID (previously implied by DynamicUser).

Fixes: NixOS#339557
@JamieMagee
JamieMagee force-pushed the esphome/nixos-static-user branch from c9deb50 to 596d3a1 Compare April 11, 2026 21:47
@JamieMagee

JamieMagee commented Apr 11, 2026 •

Copy link
Copy Markdown
Member Author

Might be breaking for people using impermanence. Systemd will migrate the data from a persistent directory into a non persisted directory which effectively deletes the files on next reboot.

Now arguably impermanence isnt NixOS core stuff, but it might affect enough users to warrant a release note entry.

@oddlama Added a release note in the latest push. It mentions the auto-migration and the impermanence caveat.

It's a shame to lose DynamicUser, and also introduce a breaking change, especially since the upstream fix might be easy if only the developers know. Is it worth raising an issue at esphome/esphome ?

@tomfitzhenry I filed platformio/platformio-core#5427 against platformio-core. The symlink issue is really platformio's path resolution, not esphome's. That said, upstream's track record on NixOS issues is "use our Docker image," so I wouldn't hold this PR for it.

@JamieMagee
JamieMagee requested a review from tomfitzhenry April 11, 2026 21:50
@nixpkgs-ci nixpkgs-ci Bot added 8.has: changelog This PR adds or changes release notes 8.has: documentation This PR adds or changes documentation labels Apr 11, 2026
@tomfitzhenry
tomfitzhenry added this pull request to the merge queue Apr 11, 2026
@tomfitzhenry

Copy link
Copy Markdown
Contributor

@tomfitzhenry I filed platformio/platformio-core#5427 against platformio-core. The symlink issue is really platformio's path resolution, not esphome's. That said, upstream's track record on NixOS issues is "use our Docker image," so I wouldn't hold this PR for it.

Great work, great PR!

Merged via the queue into NixOS:master with commit 86ab6ae Apr 11, 2026
26 checks passed
@JamieMagee
JamieMagee deleted the esphome/nixos-static-user branch April 11, 2026 23:07
@ungeskriptet ungeskriptet mentioned this pull request Apr 26, 2026
3 of 13 tasks
oddlama pushed a commit that referenced this pull request Apr 27, 2026
It looks like ExecPaths was removed in #508178, after adding it in #498811.
ExecPaths is required to fix building firmware for LibreTiny-based
devices, otherwise we get the following error:
```
sh: line 1: /var/lib/esphome/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++: Permission denied
```

Signed-off-by: David Wronek <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: changelog This PR adds or changes release notes 8.has: documentation This PR adds or changes documentation 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 12.approvals: 2 This PR was reviewed and approved by two persons.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ESPHome module: Failure to compile firmware because of DynamicUsers

6 participants