Files
lix/tests/functional2/flakes/test_config.py
T
piegamesandeldritch horrors 567348a90c testlib: default nix fixture to also test all daemon protocols (2/3)
This commit enables the parametrization for "legacy-combined" protocol.
All failing tests with that have been either fixed or disabled. Notably:

- A couple of tests (e.g. involving builders) could be made to work with
a non-local store, but this would require some refactoring to testlib in
order to make certain configuration settings generic over local and
remote operations. We've disabled those for now, in order to make
progress
- The store tests all run locally only because of their nature
- The flakes tests also all run locally only because my energy for
fixing them is limited (and it's a *lot* of test failures, with probably
little overall benefit in terms of test coverage)

Change-Id: I56fa249a64f7c17c952f688ec89e9687f2a13f12
2026-06-28 18:17:57 +02:00

67 lines
2.1 KiB
Python

from testlib.fixtures.nix import Nix
from testlib.fixtures.file_helper import with_files, File
from testlib.environ import environ
from testlib.utils import get_global_asset_pack
from pathlib import Path
from textwrap import dedent
import pytest
pytestmark = pytest.mark.no_daemon
system = environ.get("system")
files = get_global_asset_pack("simple-drv") | {
"flake.nix": File(f"""
{{
nixConfig.post-build-hook = ./echoing-post-hook.sh;
nixConfig.allow-dirty = false; # See #5621
outputs = a: {{
packages.{system}.default = import ./simple.nix;
}};
}}
""")
}
@pytest.fixture(autouse=True)
def common_init(nix: Nix, files: Path):
nix.settings.add_xp_feature("nix-command", "flakes")
hook = files / "echoing-post-hook.sh"
hook.write_text(
dedent(f"""\
#!/bin/sh
echo "ThePostHookRan as $0" > {files}/post-hook-ran
""")
)
hook.chmod(0o755)
@with_files(files)
class TestFlakeConfig:
def test_post_hook_ignored_without_accept_config(self, nix: Nix, files: Path):
nix.nix(["build"]).run().ok()
assert not (files / "post-hook-ran").exists()
def test_post_hook_ignored_with_no_accept_config(self, nix: Nix, files: Path):
nix.nix(["build", "--no-accept-flake-config"]).run().ok()
assert not (files / "post-hook-ran").exists()
def test_post_hook_runs_with_accept_config(self, nix: Nix, files: Path):
nix.nix(["build", "--accept-flake-config"]).run().ok()
hook_output = files / "post-hook-ran"
assert hook_output.exists()
first_output = hook_output.read_text()
# Make sure that the path to the post hook doesn't change if we change
# something in the flake.
# Otherwise the user would have to re-validate the setting each time.
flake = files / "flake.nix"
flake.write_text(flake.read_text() + "# comment\n")
nix.clear_store()
nix.nix(["build", "--accept-flake-config"]).run().ok()
assert hook_output.read_text() == first_output