nim-lang / RFCs

A repository for your Nim proposals.
135 stars 26 forks source link

NIM_CONF env var: allows passing in custom config before all others and apply to sub-processes #336

Open timotheecour opened 3 years ago

timotheecour commented 3 years ago

motivating example

Whenever nim introduces a (necessary) breaking change (eg; -d:nimLegacyX flags, or see https://github.com/nim-lang/Nim/pull/16924), some packages in important_packages may break, and are then either disabled or their nimble command is patched as follows:

nimble test foo
=>
nimble test foo -d:nimLegacyX

nim r tests/tbar
=>
nim r -d:nimLegacyX tests/tbar

however, this may not be enough, because tests (or nimble) may call (eg via nimscript exec or nim execShellCmd or other) further nim compilation commands, which won't have such flags propagated.

proposal

allow a simple way to pass a user config that would then automatically apply to all nim invocations via sub-processes.

We add an environment variable NIM_CONF: NIM_CONF=/pathto/customconf.nims nim args...

Environment variables are simplest way to inherit a setting for sub-processes without affecting other processes.

When NIM_CONF is non-empty, the file contained in NIM_CONF would be the 1st config file processed before all others (system, user, parent, project).

This gives the maximum flexibility (eg: allows honoring/ignoring further configs, setting --putenv, setting -d:nimLegacyX, setting --path, setting --putenv:NIMBLE_DIR, setting --gc:orc, etc)

alternative considered and rejected

set HOME or XDG_CONFIG_HOME to a custom (temporary) dir which would have the custom configuration, eg:

nimble test
=>
XDG_CONFIG_HOME=/pathto/tempHomeConfig nimble test

then CI would create /pathto/tempHomeConfig and /pathto/tempHomeConfig/nim/config.nims containing for example: -d:nimLegacyX

one problem is that XDG_CONFIG_HOME is os-specific (IIRC); furthermore, setting HOME or XDG_CONFIG_HOME can have other side effects

use cases

design goals

implementation difficulty

Araq commented 3 years ago

I prefer to pass state around explicitly. With environment variables you ask for trouble like "works on my machine, fails on the CI and works again on half of the production servers".