Skip to content

Initial experiments with /opt root for hab#10160

Draft
agadgil-progress wants to merge 1 commit intomainfrom
agadgil/hab-macos-opt
Draft

Initial experiments with /opt root for hab#10160
agadgil-progress wants to merge 1 commit intomainfrom
agadgil/hab-macos-opt

Conversation

@agadgil-progress
Copy link
Contributor

No description provided.

Signed-off-by: Abhijit Gadgil <agadgil@progress.com>
Copilot AI review requested due to automatic review settings January 16, 2026 10:52
@agadgil-progress agadgil-progress requested a review from a team as a code owner January 16, 2026 10:52
@netlify
Copy link

netlify bot commented Jan 16, 2026

Deploy Preview for chef-habitat ready!

Name Link
🔨 Latest commit 0e832a6
🔍 Latest deploy log https://app.netlify.com/projects/chef-habitat/deploys/696a1878b426780008813842
😎 Deploy Preview https://deploy-preview-10160--chef-habitat.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces experimental support for using /opt as the root filesystem path for Habitat on macOS. The changes force macOS to use /opt instead of / or the FS_ROOT environment variable, addressing potential mounting issues on macOS.

Changes:

  • Forces FS_ROOT_PATH to /opt on macOS in the core filesystem module
  • Modifies binlink path handling to accommodate the macOS-specific root path

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
components/core/src/fs.rs Adds macOS-specific logic to force FS_ROOT_PATH to "/opt" instead of respecting the FS_ROOT environment variable
components/hab/src/command/pkg/binlink.rs Adds macOS-specific path handling for both destination and source paths in the binlink function

Comment on lines +153 to +155
// For MacOS we just force it to "/opt" as other values can potentially not be
// mountable.
PathBuf::from("/opt")
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

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

Forcing FS_ROOT_PATH to '/opt' on macOS completely ignores the FS_ROOT_ENVVAR environment variable, which breaks the documented behavior for testing and creating self-contained root filesystems. This is inconsistent with Windows and Linux where the environment variable is respected. Consider allowing FS_ROOT_ENVVAR to override the default on macOS, or add a comment explaining why this limitation is necessary for the experimental feature.

Suggested change
// For MacOS we just force it to "/opt" as other values can potentially not be
// mountable.
PathBuf::from("/opt")
// On macOS, default to "/opt" for mountability reasons, but still allow
// FS_ROOT_ENVVAR to override this default for testing and self-contained
// root filesystems.
match henv::var(FS_ROOT_ENVVAR) {
Ok(root) => PathBuf::from(root),
Err(_) => PathBuf::from("/opt"),
}

Copilot uses AI. Check for mistakes.
Comment on lines +127 to +131
let dst_path = if cfg!(target_os = "macos") {
dest_path
} else {
&fs_root_path.join(dest_path.strip_prefix("/")?)
};
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

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

When cfg!(target_os = 'macos') is true, dst_path is set to dest_path directly without joining with fs_root_path. However, at line 150, the src path is joined with fs_root_path for macOS. This creates an inconsistency where binlinks will be created in the system directory (e.g., /usr/bin) rather than within the fs_root_path (e.g., /opt/hab/...). This could cause permission errors or unintended system modification. Either both paths should respect fs_root_path, or the logic needs clarification about why destination and source are treated differently.

Suggested change
let dst_path = if cfg!(target_os = "macos") {
dest_path
} else {
&fs_root_path.join(dest_path.strip_prefix("/")?)
};
let dst_path = &fs_root_path.join(dest_path.strip_prefix("/")?);

Copilot uses AI. Check for mistakes.
Comment on lines 146 to +151
if cfg!(target_os = "windows") {
src = fs_root_path.join(src.strip_prefix("/")?);
}
if cfg!(target_os = "macos") {
src = fs_root_path.join(src.strip_prefix("/")?);
}
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

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

This macOS-specific code duplicates the Windows logic from lines 146-148. Consider consolidating these platform-specific path adjustments into a single conditional block or extracting them into a helper function to reduce code duplication. For example: 'if cfg!(any(target_os = "windows", target_os = "macos")) { src = fs_root_path.join(src.strip_prefix("/")?); }'.

Suggested change
if cfg!(target_os = "windows") {
src = fs_root_path.join(src.strip_prefix("/")?);
}
if cfg!(target_os = "macos") {
src = fs_root_path.join(src.strip_prefix("/")?);
}
if cfg!(any(target_os = "windows", target_os = "macos")) {
src = fs_root_path.join(src.strip_prefix("/")?);
}

Copilot uses AI. Check for mistakes.
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.

1 participant