diff --git a/lib/clanTest/flake-module.nix b/lib/clanTest/flake-module.nix index 4e140a251..214615981 100644 --- a/lib/clanTest/flake-module.nix +++ b/lib/clanTest/flake-module.nix @@ -158,14 +158,26 @@ in ''; # the test's flake.nix with locked clan-core input - flakeForSandbox = hostPkgs.runCommand "offline-flake-for-test-${config.name}" { } '' - cp -r ${config.clan.directory} $out - chmod +w -R $out - substituteInPlace $out/flake.nix \ - --replace-fail \ - "https://git.clan.lol/clan/clan-core/archive/main.tar.gz" \ - "${clan-core.packages.${hostPkgs.system}.clan-core-flake}" - ''; + flakeForSandbox = + hostPkgs.runCommand "offline-flake-for-test-${config.name}" + { + nativeBuildInputs = [ hostPkgs.nix ]; + } + '' + cp -r ${config.clan.directory} $out + chmod +w -R $out + substituteInPlace $out/flake.nix \ + --replace-fail \ + "https://git.clan.lol/clan/clan-core/archive/main.tar.gz" \ + "${clan-core.packages.${hostPkgs.system}.clan-core-flake}" + + # Create a proper lock file for the test flake + export HOME=$(mktemp -d) + nix flake lock $out \ + --extra-experimental-features 'nix-command flakes' \ + --override-input clan-core ${clan-core.packages.${hostPkgs.system}.clan-core-flake} \ + --override-input nixpkgs ${clan-core.inputs.nixpkgs} + ''; in { imports = [ diff --git a/pkgs/clan-cli/clan_cli/tests/fixtures_flakes.py b/pkgs/clan-cli/clan_cli/tests/fixtures_flakes.py index 62b77f5ea..fefd8a262 100644 --- a/pkgs/clan-cli/clan_cli/tests/fixtures_flakes.py +++ b/pkgs/clan-cli/clan_cli/tests/fixtures_flakes.py @@ -14,6 +14,7 @@ from clan_cli.tests import age_keys from clan_cli.tests.fixture_error import FixtureError from clan_cli.tests.root import CLAN_CORE from clan_cli.tests.temporary_dir import TEMPDIR +from clan_lib import cmd from clan_lib.dirs import ( TemplateType, clan_templates, @@ -23,7 +24,7 @@ from clan_lib.dirs import ( from clan_lib.flake import Flake from clan_lib.locked_open import locked_open from clan_lib.machines.machines import Machine -from clan_lib.nix import nix_test_store +from clan_lib.nix import nix_command, nix_test_store log = logging.getLogger(__name__) @@ -86,6 +87,11 @@ def substitute( print(f"flake: {flake}") file.write_text(buf) + # Lock the flake after substitution if clan_core was replaced + if clan_core_flake: + flake_dir = file.parent + cmd.run(nix_command(["flake", "lock"]), cmd.RunOpts(cwd=flake_dir)) + class FlakeForTest(NamedTuple): path: Path