Skip to content

Conversation

@peytonr18
Copy link
Contributor

@peytonr18 peytonr18 commented Jan 30, 2026

Summary

This PR replaces the nix crate with rustix and users crates for user lookups and file ownership operations. This change improves long-term maintainability by moving to more focused, stable dependencies.

Motivation

The current nix dependency is used in a very limited way (user lookups and chown), but introduces several long‑term risks:

  • Maintenance status: Currently marked as "looking-for-maintainer" on crates.io
  • API volatility: 71 releases since 2014 with frequent breaking changes
  • Broad scope: Wraps many Unix APIs, making it prone to churn

The replacement crates offer better stability.

Changes

Code Updates

provision/ssh.rs --> Replace nix::unistd::chown with rustix::fs::chown; introduce SshUser helper
provision/mod.rs --> Replace nix::unistd::User::from_name with users::get_user_by_name
provision/mod.rs --> Replace nix::unistd::User::from_name with users::get_user_by_name

Ssh User

The nix::unistd::User type exposes mutable public fields, which allowed tests to override values such as the home directory. The users::User type is immutable and getter-only.

To preserve testability without relying on mutable system structs, this PR introduces a small SshUser data holder that can be:

  • Constructed from a real users::User in production
  • Constructed directly with test-controlled values in unit tests

Advantages:

  • Reduced dependency surface and churn
  • Actively maintained libraries with clearer ownership
  • Stronger safety guarantees via rustix I/O-safe abstractions
  • Cleaner separation between syscalls and user database access

Disadvantages:

  • Introduces an additional dependency (users) for user lookups
  • Minor API differences (UID/GID types, getter-based access)
  • Less granular error reporting for failed user lookups

…ions

Replace the nix crate dependency with rustix (for chown syscall) and
users (for user lookups).

Key changes:
- Replace nix::unistd::chown with rustix::fs::chown
- Replace nix::unistd::User::from_name with users::get_user_by_name
- Introduce SshUser struct to hold user info for SSH provisioning
- Update error type from nix::Error to rustix::io::Errno

The SshUser struct is needed because users::User is immutable (unlike
nix::unistd::User which had mutable public fields), requiring a simple
wrapper for test flexibility.
@peytonr18
Copy link
Contributor Author

I believe once we merge in #279 , the CI will pass for this PR.

Resolved conflicts in libazureinit/Cargo.toml and libazureinit/src/provision/ssh.rs
by keeping rustix and users crates instead of nix, which is the purpose of this PR.
@peytonr18 peytonr18 force-pushed the probertson-replace-nix branch from 81ac31f to 0177623 Compare February 3, 2026 22:46
Copy link
Contributor

@cjp256 cjp256 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Copy link
Contributor

@cadejacobson cadejacobson left a comment

Choose a reason for hiding this comment

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

E2E logs look good!

@cjp256 cjp256 merged commit d2692a2 into Azure:main Feb 3, 2026
15 checks passed
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