If running ghw in an environment with a non-standard root (like a container), you can redirect where ghw looks for system files (e.g., /proc, /sys).
Via CLI:
Set the GHW_CHROOT environment variable to the alternate root path.
Programmatically:
- Override Root: Use
ghw.WithChroot(path) to set a new root mountpoint. - Override Specific Paths: Use
ghw.WithPathOverrides(mapping) to provide a ghw.PathOverrides map, which allows mapping specific directories (e.g., /proc to /host-proc). This is composable with WithChroot.
Note: These features are specifically useful for containers where host filesystems are bind-mounted to non-standard locations.
// Override root
cpu, err := ghw.CPU(ghw.WithChroot("/host"))
// Override specific paths
cpu, err := ghw.CPU(ghw.WithPathOverrides(ghw.PathOverrides{
"/proc": "/host-proc",
"/sys": "/host-sys",
}))