Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 68 additions & 4 deletions pkg/defaults/defaults_darwin.go
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.

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

Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@

// This is a dummy file to allow usage of library functions
// on Darwin-based systems.
// All functions and variables are empty/no-ops
// Most functions and variables are stubs/no-ops

package defaults

import gocni "github.com/containerd/go-cni"
import (
"fmt"
"os"
"path/filepath"

gocni "github.com/containerd/go-cni"
)

const (
AppArmorProfileName = ""
Expand All @@ -33,15 +39,24 @@ func CNIPath() string {
}

func CNIRuntimeDir() (string, error) {
if os.Geteuid() != 0 {
return filepath.Join(xdgRuntimeDir(), "cni"), nil
}
return "/var/run/cni", nil
}

func CNINetConfPath() string {
if os.Geteuid() != 0 {
return filepath.Join(xdgConfigHome(), "cni", "net.d")
}
return gocni.DefaultNetDir
}

func DataRoot() string {
return "/var/lib/nerdctl"
if os.Geteuid() == 0 {
return "/var/lib/nerdctl"
}
return filepath.Join(xdgDataHome(), "nerdctl")
}

func CgroupManager() string {
Expand All @@ -53,17 +68,66 @@ func CgroupnsMode() string {
}

func NerdctlTOML() string {
if os.Geteuid() != 0 {
return filepath.Join(xdgConfigHome(), "nerdctl", "nerdctl.toml")
}
return "/etc/nerdctl/nerdctl.toml"
}

func HostsDirs() []string {
return []string{}
if os.Geteuid() != 0 {
xch := xdgConfigHome()
return []string{
filepath.Join(xch, "containerd", "certs.d"),
filepath.Join(xch, "docker", "certs.d"),
}
}
return []string{"/etc/containerd/certs.d", "/etc/docker/certs.d"}
}

func HostGatewayIP() string {
return ""
}

func CDISpecDirs() []string {
if os.Geteuid() != 0 {
return []string{
filepath.Join(xdgConfigHome(), "cdi"),
filepath.Join(xdgRuntimeDir(), "cdi"),
}
}
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 xch := os.Getenv("XDG_CONFIG_HOME"); xch != "" {
return xch
}
if home := os.Getenv("HOME"); home != "" {
return filepath.Join(home, ".config")
}
if home, err := os.UserHomeDir(); err == nil && home != "" {
return filepath.Join(home, ".config")
}
return "/etc"
}

func xdgDataHome() string {
if xdh := os.Getenv("XDG_DATA_HOME"); xdh != "" {
return xdh
}
if home := os.Getenv("HOME"); home != "" {
return filepath.Join(home, ".local", "share")
}
if home, err := os.UserHomeDir(); err == nil && home != "" {
return filepath.Join(home, ".local", "share")
}
return "/var/lib"
}

func xdgRuntimeDir() string {
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

}
Loading