Skip to content

Enable users thanks to userborn#266

Merged
jfroche merged 16 commits intomainfrom
users
Feb 3, 2026
Merged

Enable users thanks to userborn#266
jfroche merged 16 commits intomainfrom
users

Conversation

@JulienMalka
Copy link
Copy Markdown
Contributor

@JulienMalka JulienMalka commented Sep 8, 2025

Note: This is still a WIP

Essentially, we load the userborn module, and add the sysinit-reactivation target in a similar manner to NixOS. We restart that target at the beginning of the activation.

  • We are also bringing on sysusers, I am not sure if we should, as far as I understand it's because evaluating the userborn module requires it.

I also tried stripping the activationScripts feature from this PR but without much success so far.

@JulienMalka JulienMalka marked this pull request as draft September 8, 2025 20:41
@r-vdp
Copy link
Copy Markdown
Member

r-vdp commented Sep 9, 2025

Great stuff!

I have some minor questions, maybe we can have a chat tomorrow?

@r-vdp
Copy link
Copy Markdown
Member

r-vdp commented Sep 9, 2025

@JulienMalka
Copy link
Copy Markdown
Contributor Author

JulienMalka commented Sep 9, 2025

This might be an issue though:

https://github.com/nikstur/userborn/blob/main/rust%2Fuserborn%2Fsrc%2Fmain.rs#L129-146

I agree. I am not sure I 100% understand how userborn handles "impure" users/groups, I am trying to get a better understanding.
This test show that is does in some way, but I am not sure exactly how yet. Available tomorrow to look at this if you want, I'll contact you privately for this.

@jfroche
Copy link
Copy Markdown
Member

jfroche commented Sep 17, 2025

I have just realized that we end with a broken /etc/passwd (as we don't have /run/current-system [yet?]):

root:x:0:0:System administrator:/root:/run/current-system/sw/bin/bash
nobody:x:65534:65534:Unprivileged account (don't use!):/var/empty:/run/current-system/sw/bin/nologin

@r-vdp
Copy link
Copy Markdown
Member

r-vdp commented Sep 17, 2025

I have just realized that we end with a broken /etc/passwd (as we don't have /run/current-system [yet?]):

root:x:0:0:System administrator:/root:/run/current-system/sw/bin/bash
nobody:x:65534:65534:Unprivileged account (don't use!):/var/empty:/run/current-system/sw/bin/nologin

There is an equivalent directory, but not the same because we want to support running system manager on nixos (mainly for easier testing).
So we should just use the right path there.

@JulienMalka
Copy link
Copy Markdown
Contributor Author

Interesting, I wonder where this thing is set in the module system. I wouldn't expect this to be hardcoded neither in userborn or in the users module, will check.

@zimbatm zimbatm added this to the First release milestone Oct 31, 2025
@JulienMalka
Copy link
Copy Markdown
Contributor Author

This might be an issue though:

https://github.com/nikstur/userborn/blob/main/rust%2Fuserborn%2Fsrc%2Fmain.rs#L129-146

To this point, this is correct. I just pushed a commit with a failing test case that covers this issue. I also have a modification of userborn for which the test case succeeds, that I'll be submitting today upstream.

@JulienMalka
Copy link
Copy Markdown
Contributor Author

I have just realized that we end with a broken /etc/passwd (as we don't have /run/current-system [yet?]):

root:x:0:0:System administrator:/root:/run/current-system/sw/bin/bash
nobody:x:65534:65534:Unprivileged account (don't use!):/var/empty:/run/current-system/sw/bin/nologin

To this point, I see that we can change the nologin path in userborn thanks to an env variable, but I think for the shell it may come for the module system directly, not sure exactly where it is set.

@JulienMalka
Copy link
Copy Markdown
Contributor Author

Userborn change that introduces stateful users is submitted upstream: nikstur/userborn#36

@JulienMalka
Copy link
Copy Markdown
Contributor Author

Thank you @jfroche for getting this past the finish line! I had a read at the code, looks good + test are passing!

jfroche and others added 13 commits February 3, 2026 14:30
Eval works.

Work done until now:

- add missing `system.etc` and `systemd.sysusers` options.
- vendored nixpkgs/nixos/modules/config/users-groups.nix and comment `boot.initrd`
and `environment.profiles` configs.
- import user ids and userborn modules from nixpkgs.

Currently failing on:

vm-test> [2025-08-26T09:45:23Z INFO  system_manager::activate::etc_files] Done
vm-test> [2025-08-26T09:45:23Z INFO  system_manager::activate] Activating tmp files...
vm-test> /etc/tmpfiles.d/home-directories.conf:1: Failed to resolve user 'zimbatm': No such process

Most probably because we don't create the users/group before trying to create tmpfiles.

This PR is based on #258
because `user-groups.nix` and `userborn.nix` depend on
`system.activationScripts`.
This new test impurely add a new user to the system and verifies that
the user is not garbage collected by userborn.
Add a stub option for system.activationScripts.users to satisfy
nixos/modules/services/system/userborn.nix dependency without
importing the full activationScripts module.
Check that user created outside of userborn is not locked on deactivation, while userborn-managed users are locked.
mutable users handling has been merged into userborn with nikstur/userborn#38
This commit update system-manager to use the new userborn features and
properly sequence userborn execution during activation and deactivation.

System manager ensure users exist before tmpfiles runs and managed
accounts are locked on deactivation.

Activation changes:
- Restart userborn.service after daemon-reload but before tmpfiles
- Use restart (not start) because userborn is a oneshot service with
  RemainAfterExit=true - start on an already-active service is a no-op

Deactivation changes:
- Move user locking logic from Nix shell script to Rust engine
- Add users.rs module with lock_managed_users() that calls userborn
  with empty config to lock previously managed accounts
- Set USERBORN_MUTABLE_USERS=true so only managed users are locked,
  not stateful users created outside userborn
- Create top-level deactivate.rs module for cleaner API naming
The MD variant is deprecated and will be removed in NixOS 26.05.
@jfroche jfroche merged commit 3fb43e6 into main Feb 3, 2026
3 checks passed
@jfroche jfroche deleted the users branch February 3, 2026 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants