Nim: `XDG_CONFIG_DIR` env var ignored (prevents disabling ~/.config/nim.cfg for 1 process)

Created on 1 Aug 2018  路  5Comments  路  Source: nim-lang/Nim

I tried ignoring what's in my ~/.config/nim.cfg to run test suite locally (which would otherwise fail because of things like --hint[source]=on which affect expected outputs) via

XDG_CONFIG_DIR=$HOME/config_alt/ ./koch tests

however, it was still reading ~/.config/nim.cfg as can be seen via:

XDG_CONFIG_DIR=$HOME/config_alt/ nim c --nimcache:/tmp/nim//nimcache/ -o:/tmp/nim//app -r '--hint[Conf]=on' -f test.nim
Hint: used config file '/Users/timothee/git_clone/nim/Nim/config/nim.cfg' [Conf]
Hint: used config file '/Users/timothee/.config/nim.cfg' [Conf]
Hint: used config file '/Users/timothee/git_clone/nim/timn/nim.cfg' [Conf]

that's odd because getConfigDir should read XDG_CONFIG_DIR (I'm on OSX):

proc getConfigDir*(): string {.rtl, extern: "nos$1",
    tags: [ReadEnvEffect, ReadIOEffect].} =
    when defined(windows): return string(getEnv("APPDATA")) & "\\"
    elif getEnv("XDG_CONFIG_DIR"): return string(getEnv("XDG_CONFIG_DIR")) & "/"
    else: return string(getEnv("HOME")) & "/.config/"

NOTE: if I redefine HOME instead (eg via HOME=$HOME/config_alt/) this causes other issues, eg:

HOME=$HOME/config_alt/ nim c --nimcache:/tmp/nim//nimcache/ -o:/tmp/nim//app -r '--hint[Conf]=on' test.nim

Error: getAppFilename failed. (Error was: Unable to read /Users/timothee/config_alt//.choosenim/current. (Error was: No installation has been chosen. (File missing: /Users/timothee/config_alt//.choosenim/current)))

Note: simply renaming temporarily ~/.config/nim.cfg is not a viable option, as other processes might depend on it while the cmd running via over-ridden XDG_CONFIG_DIR is running (eg XDG_CONFIG_DIR=$HOME/config_alt/ ./koch tests which takes time)

EDIT

somewhat related to https://github.com/nim-lang/Nim/pull/8585 Uses XDG_CACHE_HOME if available #8585

OArch specific

All 5 comments

And where do we claim to support XDG_CONFIG_DIR? Maybe the OS shouldn't throw a never ending clusterfuck of "conventions" that "good" software must follow at application developers.

@Araq

And where do we claim to support XDG_CONFIG_DIR?

it's both in the docs in web/news/e031_version_0_16_2.rst:

ospaths.getConfigDir now conforms to the XDG Base Directory specification on non-Windows OSs. It returns the value of the XDG_CONFIG_DIR environment variable if it is set, and returns the default configuration directory, "~/.config/", otherwise.

as well as in the code in lib/pure/ospaths.nim ( in getEnv("XDG_CONFIG_DIR"))

XDG_CONFIG_DIR is useful for precisely the use case I was using it as

I guess the problem is that nim c -r doesn't pass the env var to your executable?

The compiler's documentation does not mention XDB_CONFIG_DIR.

as mentioned by @kaushalmodi in another issue (https://github.com/nim-lang/Nim/issues/8661#issuecomment-413631993), the root cause is that we were using the wrong env var XDG_CONFIG_DIR; it should've been XDG_CONFIG_HOME ; this PR https://github.com/nim-lang/Nim/pull/8662 will fix it!

EDIT => there was another bug, which I'm fixing here: https://github.com/nim-lang/Nim/pull/8680

Was this page helpful?
0 / 5 - 0 ratings