mirror of
https://github.com/NixOS/nix.git
synced 2025-11-10 04:26:01 +01:00
Rather than having store implementations return a free-form URI string, have them return a `StoreReference`. This reflects that fact that this method is supposed to invert `resolveStoreConfig`, which goes from a `StoreReference` to some `StoreConfig` concrete derived class (based on the registry). `StoreConfig::getUri` is kept only as a convenience for the common case that we want to immediately render the `StoreReference`. A few tests were changed to use `local://` not `local`, since `StoreReference` does not encode the `local` and `daemon` shorthands (and instead desugars them to `local://` and `unix://` right away). I think that is fine. `local` and `daemon` still work as input.
73 lines
2.4 KiB
Bash
Executable file
73 lines
2.4 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
source common.sh
|
|
|
|
# Different versions of the Nix daemon normalize or don't normalize
|
|
# store URLs, plus NIX_REMOTE (per the test suite) might not be using on
|
|
# store URL in normal form, so the easiest thing to do is normalize URLs
|
|
# after the fact before comparing them for equality.
|
|
normalize_nix_store_url () {
|
|
local url="$1"
|
|
case "$url" in
|
|
'auto' )
|
|
# Need to actually ask Nix in this case
|
|
echo "$defaultStore"
|
|
;;
|
|
'local://'* )
|
|
# To not be captured by next pattern
|
|
echo "$url"
|
|
;;
|
|
local | 'local?'* )
|
|
echo "local://${url#local}"
|
|
;;
|
|
daemon | 'daemon?'* )
|
|
echo "unix://${url#daemon}"
|
|
;;
|
|
* )
|
|
echo "$url"
|
|
;;
|
|
esac
|
|
}
|
|
|
|
STORE_INFO=$(nix store info 2>&1)
|
|
LEGACY_STORE_INFO=$(nix store ping 2>&1) # alias to nix store info
|
|
STORE_INFO_JSON=$(nix store info --json)
|
|
|
|
defaultStore="$(normalize_nix_store_url "$(echo "$STORE_INFO_JSON" | jq -r ".url")")"
|
|
|
|
# Test cases for `normalize_nix_store_url` itself
|
|
|
|
# Normalize local store
|
|
[[ "$(normalize_nix_store_url "local://")" = "local://" ]]
|
|
[[ "$(normalize_nix_store_url "local")" = "local://" ]]
|
|
[[ "$(normalize_nix_store_url "local?foo=bar")" = "local://?foo=bar" ]]
|
|
|
|
# Normalize unix domain socket remote store
|
|
[[ "$(normalize_nix_store_url "unix://")" = "unix://" ]]
|
|
[[ "$(normalize_nix_store_url "daemon")" = "unix://" ]]
|
|
[[ "$(normalize_nix_store_url "daemon?x=y")" = "unix://?x=y" ]]
|
|
|
|
# otherwise unchanged
|
|
[[ "$(normalize_nix_store_url "https://site")" = "https://site" ]]
|
|
|
|
nixRemoteOrDefault=$(normalize_nix_store_url "${NIX_REMOTE:-"auto"}")
|
|
|
|
check_human_readable () {
|
|
[[ "$(normalize_nix_store_url "$(echo "$1" | grep 'Store URL:' | sed 's^Store URL: ^^')")" = "${nixRemoteOrDefault}" ]]
|
|
}
|
|
check_human_readable "$STORE_INFO"
|
|
check_human_readable "$LEGACY_STORE_INFO"
|
|
|
|
if [[ -v NIX_DAEMON_PACKAGE ]] && isDaemonNewer "2.7.0pre20220126"; then
|
|
DAEMON_VERSION=$("$NIX_DAEMON_PACKAGE"/bin/nix daemon --version | cut -d' ' -f3)
|
|
echo "$STORE_INFO" | grep "Version: $DAEMON_VERSION"
|
|
[[ "$(echo "$STORE_INFO_JSON" | jq -r ".version")" == "$DAEMON_VERSION" ]]
|
|
fi
|
|
|
|
|
|
expect 127 NIX_REMOTE=unix:"$PWD"/store nix store info || \
|
|
fail "nix store info on a non-existent store should fail"
|
|
|
|
TODO_NixOS
|
|
|
|
[[ "$(normalize_nix_store_url "$(echo "$STORE_INFO_JSON" | jq -r ".url")")" == "${nixRemoteOrDefault}" ]]
|