Add NVCT_CONFIG_FILE_PATH envvar

This change adds support for explicitly specifying the path
to the config file through an environment variable.
The NVCT_CONFIG_FILE_PATH variable is used for both the nvidia-container-runtime
and nvidia-container-runtime-hook.

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar 2024-10-30 13:43:49 +01:00
parent 1a83552aa6
commit a1e98539d0
No known key found for this signature in database
2 changed files with 6 additions and 0 deletions

View File

@ -174,6 +174,7 @@ func main() {
Name: "config",
Destination: &a.configFile,
Usage: "The path to the configuration file to use",
EnvVars: []string{config.FilePathOverrideEnvVar},
},
}

View File

@ -30,6 +30,8 @@ import (
)
const (
FilePathOverrideEnvVar = "NVCTK_CONFIG_FILE_PATH"
configOverride = "XDG_CONFIG_HOME"
configFilePath = "nvidia-container-runtime/config.toml"
@ -71,6 +73,9 @@ type Config struct {
// GetConfigFilePath returns the path to the config file for the configured system
func GetConfigFilePath() string {
if configFilePathOverride := os.Getenv(FilePathOverrideEnvVar); configFilePathOverride != "" {
return configFilePathOverride
}
if XDGConfigDir := os.Getenv(configOverride); len(XDGConfigDir) != 0 {
return filepath.Join(XDGConfigDir, configFilePath)
}