colima icon indicating copy to clipboard operation
colima copied to clipboard

`XDG_CONFIG_HOME` still ignored

Open tj-smith47 opened this issue 1 year ago • 6 comments

Description

If you start colima for the first time with XDG_CONFIG_HOME set, it respects it and generates the config dir in the appropriate place. The next time you restart it, it creates another config directory in your home directory. I saw another issue stating this was resolved, but it's not.

Version

colima version 0.9.1
git commit: 0cbf719f5409ce04b9f0607b681c005d2ff7d94a
WARN[0000] found ~/.colima, ignoring $XDG_CONFIG_HOME...
WARN[0000] delete ~/.colima to use $XDG_CONFIG_HOME as config directory
WARN[0000] or run `mv ~/.colima "/Users/tjsmith/.config/colima"
runtime: docker
arch: aarch64
client: v28.5.1
server: v28.4.0

I don't have qemu-img, I use virtiofs, and it wasn't installed as a required package via homebrew.

Operating System

  • [ ] macOS Intel <= 13 (Ventura)
  • [ ] macOS Intel >= 14 (Sonoma)
  • [ ] Apple Silicon <= 13 (Ventura)
  • [x] Apple Silicon >= 14 (Sonoma)
  • [ ] Linux

Output of colima status

WARN[0000] found ~/.colima, ignoring $XDG_CONFIG_HOME...
WARN[0000] delete ~/.colima to use $XDG_CONFIG_HOME as config directory
WARN[0000] or run 'mv ~/.colima "/Users/tjsmith/.config/colima"'
WARN[0000] found ~/.colima, ignoring $XDG_CONFIG_HOME...
WARN[0000] delete ~/.colima to use $XDG_CONFIG_HOME as config directory
WARN[0000] or run 'mv ~/.colima "/Users/tjsmith/.config/colima"'
INFO[0000] colima is running using macOS Virtualization.Framework
INFO[0000] arch: aarch64
INFO[0000] runtime: docker
INFO[0000] mountType: virtiofs
INFO[0000] docker socket: unix:///Users/tjsmith/.colima/default/docker.sock
INFO[0000] containerd socket: unix:///Users/tjsmith/.colima/default/containerd.sock

Reproduction Steps

  1. Run colima start --cpu 11 --memory 12 --disk 120 --vm-type vz --mount-type virtiofs --mount-inotify --vz-rosetta (only ~/.config/colima exists)
  2. Restart colima as a homebrew service (colima stop && brew services start colima).
  3. Now ~/.colima exists

Expected behaviour

Only 1 config dir, at ~/.config/colima

Additional context

No response

tj-smith47 avatar Oct 13 '25 22:10 tj-smith47

Update - I've found that this issue is specific to starting colima as a homebrew service. If you add some XML to /opt/homebrew/opt/colima/homebrew.mxcl.colima.plist before starting it the second time, it will respect the additional config:

	<key>EnvironmentVariables</key>
	<dict>
		<key>PATH</key>
		<string>/opt/homebrew/bin:/opt/homebrew/sbin:/usr/bin:/bin:/usr/sbin:/sbin</string>
		<key>XDG_CONFIG_HOME</key>
		<string>/Users/tjsmith/.config</string>
	</dict>

I'm not sure what if anything you all can do to better detect an existing colima directory and not re-create it (or even just check the most common locations) as it seems to be somewhat of a homebrew problem - but if you found a way, it would be much appreciated.

tj-smith47 avatar Oct 13 '25 22:10 tj-smith47

At minimum, can we add this note to the section on auto-starting colima? https://github.com/abiosoft/colima/blob/main/docs/FAQ.md#does-colima-support-autostart

tj-smith47 avatar Oct 20 '25 16:10 tj-smith47

@tj-smith47 How are you setting the XDG* variables?

If via a bash/zsh rc script, then they only exist for an acitve terminal session, and available only for applications that directly launched from that terminal. Which excludes applications launched by Finder, Spotlight, Launch Daemon (System, Root, and User), etc.

About 10-15 years ago, Apple changed the behaviour to fully isolate apps from accessing any environment variables, and removed various configuration (/etc/launchd.conf) supporting the insecure practise. Apple employees have reaffirmed that applications ported to Mac, and GUI apps must not rely on environment variables existing or being accessible.

As many developers have found out

This problem is most common on macOS, as Apple makes it exceedingly difficult to setup environment variables system-wide

I gave up trying a few years back. Apple keeps removing workarounds of setting environment variables to all applications automatically.
The most widely spread means of doing so, is using the legacy (legacy back in 2014) subcommand launchctl setenv ..., which sets env variables for subsequent applications opened for the current session. This is done by creating custom root and user launch services, and have each call launchctl setenv. Note, Apple does not guarantee ordering of startup services, and such script may or may not run before the colima service.

cawolfdev avatar Nov 12 '25 19:11 cawolfdev

@cawolfdev I actually ended up having to put it at ~/Library/LaunchAgents/com.user.environment.plist, containing:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>com.user.environment</string>
  <key>ProgramArguments</key>
  <array>
    <string>launchctl</string>
    <string>setenv</string>
    <string>XDG_CONFIG_HOME</string>
    <string>/Users/tjsmith/.config</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
</dict>
</plist>

It works reliably - though, I do have an issue that whenever I reboot my macbook, I have to restart colima (again, enabled as a homebrew service). I'm not sure it's related. I usually just bring colima down before a reboot / upgrade, and then back up after I sign in.

tj-smith47 avatar Nov 12 '25 23:11 tj-smith47

I ran into the same issue when using brew services to start Colima. Since launchd doesn't inherit shell environment variables like XDG_CONFIG_HOME, Colima always recreates ~/.colima on startup, causing a mismatch with the XDG path.

A simple symlink workaround resolved it for me:

colima stop
brew services stop colima
rm -rf ~/.colima
ln -s ~/.config/colima ~/.colima
brew services start colima

This way, both launchd (which writes to ~/.colima) and the shell (which expects ~/.config/colima) point to the same location. No need to modify the plist or use launchctl setenv.

So far it's working well for me, but I haven't tested it extensively yet (e.g. across reboots, brew upgrade colima, colima delete, etc.). I'll update this comment if I run into any issues.

Hope this helps others hitting the same issue.

him0 avatar Mar 22 '26 17:03 him0

Related discussion in the Homebrew repo: https://github.com/orgs/Homebrew/discussions/6196

I ended up doing this[^ref]:

# delete old artifacts
brew services stop colima
colima stop
colima delete --data
rm -r ~/.colima/

# new launch agent with env vars set
perl -0p \
    -e 's|(<key>EnvironmentVariables</key>.+?)\n(\s+)</dict>|$1' \
    -e '$2$2<key>COLIMA_HOME</key>' \
    -e '$2$2<string>$ENV{XDG_CONFIG_HOME}/colima</string>' \
    -e '$2$2<key>DOCKER_CONFIG</key>' \
    -e '$2$2<string>$ENV{XDG_CONFIG_HOME}/docker</string>' \
    -e '$2</dict>|s' \
    ${HOME}/Library/LaunchAgents/homebrew.mxcl.colima.plist \
    >| ${HOME}/Library/LaunchAgents/com.${USER}.colima.plist

# restart service with new launch agent
brew services restart colima --file=${HOME}/Library/LaunchAgents/com.${USER}.colima.plist

[^ref]: My comment in the other thread: modifying/creating a new plist file and then starting the brew service with the --file= flag

andelink avatar May 30 '26 17:05 andelink