Skip to content

Conversation

@valpackett
Copy link
Contributor

For embedded appliance-style applications, we would like to avoid the ~100ms boot time hit that comes from running userborn or sysusers by pre-baking the final password files directly into the system closure.

Turns out, userborn is trivial to run at build time instead of boot time, so let's introduce a new "baked" mode that directly places the files into an immutable /etc.

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.

Add a 👍 reaction to pull requests you find important.

@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 Nov 28, 2025
@valpackett valpackett marked this pull request as ready for review November 28, 2025 10:55
@Mic92 Mic92 requested a review from nikstur November 28, 2025 10:57
@nixpkgs-ci nixpkgs-ci bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Nov 28, 2025
Copy link
Contributor

@nikstur nikstur left a comment

Choose a reason for hiding this comment

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

This is generally a bad idea.

You can only sensible allocated UIDs impurely, i.e. when the system is running because you always need to have the state of the password files (i.e. from users changing between generations).

The only situation where this mode is acceptable is if you never change users during the entire lifetime of the system, i.e. when you do not switch generations but delete and re-create the entire image for an update.

Otherwise it's potentially dangerous because of UID/GID re-use. Please see this part of the Userborn readme for an example of why UID/GID re-use is bad.

If you're thinking of the acceptable use-case describe above, we need to make this very clear and point out the pitfalls in the docs. I'd also prefer if this mode was called static because baked is not very descriptive IMO.

@valpackett
Copy link
Contributor Author

Yes, by "embedded appliance-style applications" I mean systems that don't use NixOS generations at all. We're currently doing this for application VMs that are built with raw nix build and are entirely stateless.

What would be a good assertion for "generations / typical nixos management aren't used"?

Yeah, I thought about static being an alternative name, will rename.

@inthesquarehole
Copy link

Yes, by "embedded appliance-style applications" I mean systems that don't use NixOS generations at all. We're currently doing this for application VMs that are built with raw nix build and are entirely stateless.

What would be a good assertion for "generations / typical nixos management aren't used"?

Assert that nixos-rebuild{,-ng} shouldn't be installed.

@nikstur
Copy link
Contributor

nikstur commented Nov 30, 2025

Yes, by "embedded appliance-style applications" I mean systems that don't use NixOS generations at all. We're currently doing this for application VMs that are built with raw nix build and are entirely stateless.
What would be a good assertion for "generations / typical nixos management aren't used"?

Assert that nixos-rebuild{,-ng} shouldn't be installed.

You could do that via system.switch.enable.

EDIT: Please note, however, that this doesn't solve all cases. When you build an image based system and update it with systemd-sysupdate for example, you should still not use the static mode. However, I think, this assert would be good enough to prohibit most frivolous use.

@valpackett valpackett changed the title nixos/userborn: introduce config.services.userborn.baked mode nixos/userborn: introduce config.services.userborn.static mode Dec 4, 2025
Copy link
Contributor

@nikstur nikstur left a comment

Choose a reason for hiding this comment

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

Please add test for this. Otherwise it's very hard to maintain long-term.

For embedded appliance-style applications, we would like to avoid the
~100ms boot time hit that comes from running userborn or sysusers by
pre-baking the final password files directly into the system closure.

Turns out, userborn is trivial to run at build time instead of boot time,
so let's introduce a new "baked" static mode that directly places the files
into an immutable /etc.
@valpackett
Copy link
Contributor Author

Is one test sufficient or should there be variants for mutable/immutable /etc and users?

Copy link
Contributor

@nikstur nikstur left a comment

Choose a reason for hiding this comment

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

Is one test sufficient or should there be variants for mutable/immutable /etc and users?

One is fine for now.

Thank you for the work! Definitely an interesting use case. I appreciate the benchmarking that you have done beforehand.


name = "userborn-static";

meta.maintainers = with lib.maintainers; [ nikstur ];
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you want to add yourself here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

eh, don't think it would necessary..

@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 Dec 7, 2025
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: 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.

3 participants