Skip to content
Snippets Groups Projects
Unverified Commit 461cf2b8 authored by Christian Kampka's avatar Christian Kampka
Browse files

Add NIX_CONFIG env var for applying nix.conf overrides

parent 21244e10
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,9 @@ By default Nix reads settings from the following places: ...@@ -19,6 +19,9 @@ By default Nix reads settings from the following places:
and `XDG_CONFIG_HOME`. If these are unset, it will look in and `XDG_CONFIG_HOME`. If these are unset, it will look in
`$HOME/.config/nix.conf`. `$HOME/.config/nix.conf`.
- If `NIX_OPTIONS` is set, its contents is treated as the contents of
a configuration file.
The configuration files consist of `name = The configuration files consist of `name =
value` pairs, one per line. Other files can be included with a line like value` pairs, one per line. Other files can be included with a line like
`include `include
......
...@@ -81,6 +81,11 @@ Most Nix commands interpret the following environment variables: ...@@ -81,6 +81,11 @@ Most Nix commands interpret the following environment variables:
Overrides the location of the system Nix configuration directory Overrides the location of the system Nix configuration directory
(default `prefix/etc/nix`). (default `prefix/etc/nix`).
- `NIX_OPTIONS`
Applies settings from Nix configuration from the environment.
The content is treated as if it was read from a Nix configuration file.
Settings are separated by the newline character.
- `NIX_USER_CONF_FILES` - `NIX_USER_CONF_FILES`
Overrides the location of the user Nix configuration files to load Overrides the location of the user Nix configuration files to load
from (defaults to the XDG spec locations). The variable is treated from (defaults to the XDG spec locations). The variable is treated
......
...@@ -86,6 +86,12 @@ void loadConfFile() ...@@ -86,6 +86,12 @@ void loadConfFile()
for (auto file = files.rbegin(); file != files.rend(); file++) { for (auto file = files.rbegin(); file != files.rend(); file++) {
globalConfig.applyConfigFile(*file); globalConfig.applyConfigFile(*file);
} }
auto nixConfEnv = getEnv("NIX_CONFIG");
if (nixConfEnv.has_value()) {
globalConfig.applyConfig(nixConfEnv.value(), "NIX_CONFIG");
}
} }
std::vector<Path> getUserConfigFiles() std::vector<Path> getUserConfigFiles()
......
...@@ -16,3 +16,12 @@ here=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")") ...@@ -16,3 +16,12 @@ here=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")
export NIX_USER_CONF_FILES=$here/config/nix-with-substituters.conf export NIX_USER_CONF_FILES=$here/config/nix-with-substituters.conf
var=$(nix show-config | grep '^substituters =' | cut -d '=' -f 2 | xargs) var=$(nix show-config | grep '^substituters =' | cut -d '=' -f 2 | xargs)
[[ $var == https://example.com ]] [[ $var == https://example.com ]]
# Test that it's possible to load config from the environment
prev=$(nix show-config | grep '^cores' | cut -d '=' -f 2 | xargs)
export NIX_CONFIG="cores = 4242"$'\n'"experimental-features = nix-command flakes"
exp_cores=$(nix show-config | grep '^cores' | cut -d '=' -f 2 | xargs)
exp_features=$(nix show-config | grep '^experimental-features' | cut -d '=' -f 2 | xargs)
[[ $prev != $exp_cores ]]
[[ $exp_cores == "4242" ]]
[[ $exp_features == "nix-command flakes" ]]
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment