nixVersions: give unit tests access to a $HOME directory

Also, don't try to access cache.nixos.org in the libstore unit tests.
We have to disable the test in versions prior to 2.31; that's OK, since
it was being skipped when run under Nix anyway before that.

(cherry picked from commit 01388b3e78582553cc30ee772db5b5aba8d89edd)

Co-authored-by: Philip Taron <philip.taron@gmail.com>
This commit is contained in:
Eelco Dolstra
2025-08-30 06:23:07 -07:00
committed by Philip Taron
co-authored by Philip Taron
parent 325375d3ff
commit d593eadfc6
2 changed files with 20 additions and 23 deletions
@@ -42,18 +42,14 @@ mkMesonExecutable (finalAttrs: {
{
meta.broken = !stdenv.hostPlatform.emulatorAvailable buildPackages;
}
(
lib.optionalString stdenv.hostPlatform.isWindows ''
export HOME="$PWD/home-dir"
mkdir -p "$HOME"
''
+ ''
export _NIX_TEST_UNIT_DATA=${resolvePath ./data}
export NIX_CONFIG="extra-experimental-features = flakes"
${stdenv.hostPlatform.emulator buildPackages} ${lib.getExe finalAttrs.finalPackage}
touch $out
''
);
(''
export _NIX_TEST_UNIT_DATA=${resolvePath ./data}
export NIX_CONFIG="extra-experimental-features = flakes"
export HOME="$TMPDIR/home"
mkdir -p "$HOME"
${stdenv.hostPlatform.emulator buildPackages} ${lib.getExe finalAttrs.finalPackage}
touch $out
'');
};
};
@@ -41,6 +41,10 @@ mkMesonExecutable (finalAttrs: {
mesonFlags = [
];
excludedTestPatterns = lib.optionals (lib.versionOlder finalAttrs.version "2.31") [
"nix_api_util_context.nix_store_real_path_binary_cache"
];
passthru = {
tests = {
run =
@@ -59,17 +63,14 @@ mkMesonExecutable (finalAttrs: {
{
meta.broken = !stdenv.hostPlatform.emulatorAvailable buildPackages;
}
(
lib.optionalString stdenv.hostPlatform.isWindows ''
export HOME="$PWD/home-dir"
mkdir -p "$HOME"
''
+ ''
export _NIX_TEST_UNIT_DATA=${data + "/src/libstore-tests/data"}
${stdenv.hostPlatform.emulator buildPackages} ${lib.getExe finalAttrs.finalPackage}
touch $out
''
);
(''
export _NIX_TEST_UNIT_DATA=${data + "/src/libstore-tests/data"}
export HOME="$TMPDIR/home"
mkdir -p "$HOME"
${stdenv.hostPlatform.emulator buildPackages} ${lib.getExe finalAttrs.finalPackage} \
--gtest_filter=-${lib.concatStringsSep ":" finalAttrs.excludedTestPatterns}
touch $out
'');
};
};