forked from lix-project/lix
8458d98b27
Part of #7672
My main motivation is to be able to use `nix.checkConfig`[1]. This
doesn't work with Lix currently since the module uses `nix show-config`
if the Nix version is <2.20pre and `nix config show` otherwise. I think
this is the only instance where nixpkgs checks for which Nix commands
exist that affects us now, so I figured we could just perform the rename
here as well[2] and still provide the current version number[3].
I don't have a strong opinion on whether to deprecate `nix show-config`,
the warning is added there automatically.
(cherry picked from commit f300e11b056dea414d7d77bbc6e5a7dc5d9ddd41)
[1] https://nixos.org/manual/nixos/stable/options.html#opt-nix.checkConfig
[2] I should add that I don't use the "official" ways of installing Lix
because using the flake directly and callPackaging it seemed to fit
better into my workflow: I already have a little mess to make
sure Hydra from the flake uses the correct pkgs.nix and I didn't
want to complicate it further while keeping a single package-set I
can build in CI. Don't get me wrong, I think such a module for a
quick-start is very important, just giving context on why I bother
in the first place :)
[3] When we go public, I think it's worth considering to add support in
nixpkgs itself for Lix.
Change-Id: I47b4239b05cbeda3c370d2fa56ea768b768768ac
59 lines
2.6 KiB
Bash
59 lines
2.6 KiB
Bash
source common.sh
|
|
|
|
# Isolate the home for this test.
|
|
# Other tests (e.g. flake registry tests) could be writing to $HOME in parallel.
|
|
export HOME=$TEST_ROOT/userhome
|
|
|
|
# Test that using XDG_CONFIG_HOME works
|
|
# Assert the config folder didn't exist initially.
|
|
[ ! -e "$HOME/.config" ]
|
|
# Without XDG_CONFIG_HOME, creates $HOME/.config
|
|
unset XDG_CONFIG_HOME
|
|
# Run against the nix registry to create the config dir
|
|
# (Tip: this relies on removing non-existent entries being a no-op!)
|
|
nix registry remove userhome-without-xdg
|
|
# Verifies it created it
|
|
[ -e "$HOME/.config" ]
|
|
# Remove the directory it created
|
|
rm -rf "$HOME/.config"
|
|
# Run the same test, but with XDG_CONFIG_HOME
|
|
export XDG_CONFIG_HOME=$TEST_ROOT/confighome
|
|
# Assert the XDG_CONFIG_HOME/nix path does not exist yet.
|
|
[ ! -e "$TEST_ROOT/confighome/nix" ]
|
|
nix registry remove userhome-with-xdg
|
|
# Verifies the confighome path has been created
|
|
[ -e "$TEST_ROOT/confighome/nix" ]
|
|
# Assert the .config folder hasn't been created.
|
|
[ ! -e "$HOME/.config" ]
|
|
|
|
# Test that files are loaded from XDG by default
|
|
export XDG_CONFIG_HOME=$TEST_ROOT/confighome
|
|
export XDG_CONFIG_DIRS=$TEST_ROOT/dir1:$TEST_ROOT/dir2
|
|
files=$(nix-build --verbose --version | grep "User config" | cut -d ':' -f2- | xargs)
|
|
[[ $files == "$TEST_ROOT/confighome/nix/nix.conf:$TEST_ROOT/dir1/nix/nix.conf:$TEST_ROOT/dir2/nix/nix.conf" ]]
|
|
|
|
# Test that setting NIX_USER_CONF_FILES overrides all the default user config files
|
|
export NIX_USER_CONF_FILES=$TEST_ROOT/file1.conf:$TEST_ROOT/file2.conf
|
|
files=$(nix-build --verbose --version | grep "User config" | cut -d ':' -f2- | xargs)
|
|
[[ $files == "$TEST_ROOT/file1.conf:$TEST_ROOT/file2.conf" ]]
|
|
|
|
# Test that it's possible to load the config from a custom location
|
|
here=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")
|
|
export NIX_USER_CONF_FILES=$here/config/nix-with-substituters.conf
|
|
var=$(nix config show | grep '^substituters =' | cut -d '=' -f 2 | xargs)
|
|
[[ $var == https://example.com ]]
|
|
|
|
# Test that it's possible to load config from the environment
|
|
prev=$(nix config show | grep '^cores' | cut -d '=' -f 2 | xargs)
|
|
export NIX_CONFIG="cores = 4242"$'\n'"experimental-features = nix-command flakes"
|
|
exp_cores=$(nix config show | grep '^cores' | cut -d '=' -f 2 | xargs)
|
|
exp_features=$(nix config show | grep '^experimental-features' | cut -d '=' -f 2 | xargs)
|
|
[[ $prev != $exp_cores ]]
|
|
[[ $exp_cores == "4242" ]]
|
|
[[ $exp_features == "flakes nix-command" ]]
|
|
|
|
# Test that it's possible to retrieve a single setting's value
|
|
val=$(nix config show | grep '^warn-dirty' | cut -d '=' -f 2 | xargs)
|
|
val2=$(nix config show warn-dirty)
|
|
[[ $val == $val2 ]]
|