Skip to content

defaults: use user-writable data root on darwin#4842

Draft
66Ton99 wants to merge 2 commits intocontainerd:mainfrom
66Ton99:ton/darwin-dataroot
Draft

defaults: use user-writable data root on darwin#4842
66Ton99 wants to merge 2 commits intocontainerd:mainfrom
66Ton99:ton/darwin-dataroot

Conversation

@66Ton99
Copy link
Copy Markdown

@66Ton99 66Ton99 commented Apr 9, 2026

Summary

On Darwin, defaults.DataRoot() currently always returns /var/lib/nerdctl.
For regular users this can fail immediately with:

mkdir /var/lib/nerdctl: permission denied

This change makes Darwin use a user-writable default data root.

Change

In pkg/defaults/defaults_darwin.go:

  • DataRoot() now returns $HOME/.local/share/nerdctl when the home directory is available
  • falls back to /var/lib/nerdctl if home cannot be resolved

Why

This aligns the Darwin default with typical non-root usage and avoids immediate startup failures for users who run nerdctl without elevated privileges.

Scope

  • Darwin only
  • no Linux/Windows behavior changes

Validation

  • go test ./pkg/defaults ./pkg/config

Review request

A review from maintainers familiar with nerdctl default path semantics across platforms would be appreciated.

@66Ton99
Copy link
Copy Markdown
Author

66Ton99 commented Apr 9, 2026

Related downstream packaging PR:

Signed-off-by: Ton Sharp <45160296+66Ton99@users.noreply.github.com>
@66Ton99 66Ton99 force-pushed the ton/darwin-dataroot branch from 28dff3d to 45e76e3 Compare April 9, 2026 23:58
if home, err := os.UserHomeDir(); err == nil && home != "" {
return filepath.Join(home, ".local", "share", "nerdctl")
}
return "/var/lib/nerdctl"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should remain the default when EUID is 0

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in a5cdb0d. DataRoot now keeps /var/lib/nerdctl when EUID == 0.


func DataRoot() string {
if home, err := os.UserHomeDir(); err == nil && home != "" {
return filepath.Join(home, ".local", "share", "nerdctl")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

$XDG_DATA_HOME should be respected

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in a5cdb0d. For non-root on Darwin, DataRoot now respects XDG_DATA_HOME (fallback: ~/.local/share).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

All the paths should be handled consistently, not just DataRoot

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in a5cdb0d. I applied the same root/non-root + XDG convention consistently to DataRoot, CNINetConfPath, CNIRuntimeDir, NerdctlTOML, HostsDirs, and CDISpecDirs.


func DataRoot() string {
if home, err := os.UserHomeDir(); err == nil && home != "" {
return filepath.Join(home, ".local", "share", "nerdctl")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The convention should be consistent with nerdbox.
Let me cc @containerd/nerdbox-committers @containerd/nerdbox-reviewers

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed in a5cdb0d. Updated Darwin defaults to follow the same user-writable/XDG convention consistently across paths for non-root, while keeping system defaults for root.

return []string{"/etc/cdi", "/var/run/cdi"}
}

func xdgConfigHome() string {
Copy link
Copy Markdown
Member

@AkihiroSuda AkihiroSuda Apr 10, 2026

Choose a reason for hiding this comment

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

Duplicated code: https://github.com/containerd/nerdctl/blob/main/pkg/rootlessutil/xdg_linux.go

Should be consolidated to a single package (but not a single file).

if xdr := os.Getenv("XDG_RUNTIME_DIR"); xdr != "" {
return xdr
}
return fmt.Sprintf("/run/user/%d", os.Geteuid())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Inexistent on macOS

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Probably (most of) defaults_darwin.go and defaults_freebsd.go can be consolidated into a single defaults_unix.go

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.

2 participants