Compare commits
1 Commits
speed-up-v
...
lassulus
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9043365734 |
@@ -292,8 +292,24 @@ class Flake:
|
|||||||
in
|
in
|
||||||
flake.inputs.nixpkgs.legacyPackages.{config["system"]}.writeText "clan-flake-select" (builtins.toJSON [ ({" ".join([f'flake.clanInternals.lib.select "{attr}" flake' for attr in selectors])}) ])
|
flake.inputs.nixpkgs.legacyPackages.{config["system"]}.writeText "clan-flake-select" (builtins.toJSON [ ({" ".join([f'flake.clanInternals.lib.select "{attr}" flake' for attr in selectors])}) ])
|
||||||
"""
|
"""
|
||||||
build_output = run(nix_build(["--expr", nix_code])).stdout.strip()
|
cmd = nix_build(["--expr", nix_code, '-vvv'])
|
||||||
|
# breakpoint()
|
||||||
|
import subprocess
|
||||||
|
print("running nix build")
|
||||||
|
# breakpoint()
|
||||||
|
# build_output = run(cmd).stdout.strip()
|
||||||
|
import time
|
||||||
|
t = time.time()
|
||||||
|
# breakpoint()
|
||||||
|
import os
|
||||||
|
print(os.environ["HOME"])
|
||||||
|
build_output = subprocess.run(cmd, capture_output=True, text=True).stdout.strip()
|
||||||
|
print(f"ran nix build 1: {time.time() - t}")
|
||||||
|
t = time.time()
|
||||||
|
build_output = subprocess.run(cmd, capture_output=True, text=True).stdout.strip()
|
||||||
|
print(f"ran nix build 2: {time.time() - t}")
|
||||||
outputs = json.loads(Path(build_output).read_text())
|
outputs = json.loads(Path(build_output).read_text())
|
||||||
|
print("got output")
|
||||||
if len(outputs) != len(selectors):
|
if len(outputs) != len(selectors):
|
||||||
msg = f"flake_prepare_cache: Expected {len(outputs)} outputs, got {len(outputs)}"
|
msg = f"flake_prepare_cache: Expected {len(outputs)} outputs, got {len(outputs)}"
|
||||||
raise ClanError(msg)
|
raise ClanError(msg)
|
||||||
@@ -303,5 +319,7 @@ class Flake:
|
|||||||
def select(self, selector: str) -> Any:
|
def select(self, selector: str) -> Any:
|
||||||
if not self.cache.is_cached(selector):
|
if not self.cache.is_cached(selector):
|
||||||
log.info(f"Cache miss for {selector}")
|
log.info(f"Cache miss for {selector}")
|
||||||
|
print("preparing cache")
|
||||||
self.prepare_cache([selector])
|
self.prepare_cache([selector])
|
||||||
|
print("cache prepared")
|
||||||
return self.cache.select(selector)
|
return self.cache.select(selector)
|
||||||
|
|||||||
@@ -1,15 +1,30 @@
|
|||||||
from clan_cli.flake import FlakeCacheEntry
|
from clan_cli.flake import FlakeCacheEntry, Flake
|
||||||
from fixtures_flakes import ClanFlake
|
from fixtures_flakes import ClanFlake
|
||||||
|
from helpers import cli
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
def test_flake_caching(test_flake: ClanFlake) -> None:
|
@pytest.mark.with_core
|
||||||
|
def test_flake_caching(
|
||||||
|
flake: ClanFlake
|
||||||
|
) -> None:
|
||||||
testdict = {"x": {"y": [123, 345, 456], "z": "bla"}}
|
testdict = {"x": {"y": [123, 345, 456], "z": "bla"}}
|
||||||
test_cache = FlakeCacheEntry(testdict, [])
|
test_cache = FlakeCacheEntry(testdict, [])
|
||||||
assert test_cache["x"]["z"].value == "bla"
|
assert test_cache["x"]["z"].value == "bla"
|
||||||
assert test_cache.is_cached(["x", "z"])
|
assert test_cache.is_cached(["x", "z"])
|
||||||
assert test_cache.select(["x", "y", 0]) == 123
|
assert test_cache.select(["x", "y", 0]) == 123
|
||||||
assert not test_cache.is_cached(["x", "z", 1])
|
assert not test_cache.is_cached(["x", "z", 1])
|
||||||
# TODO check this, but test_flake is not a real clan flake (no clan-core, no clanInternals)
|
# TODO check this, but flake is not a real clan flake (no clan-core, no clanInternals)
|
||||||
# cmd.run(["nix", "flake", "lock"], cmd.RunOpts(cwd=test_flake.path))
|
# cli.run(["nix", "flake", "lock"], cmd.RunOpts(cwd=flake.path))
|
||||||
# flake = Flake(str(test_flake.path))
|
m1 = flake.machines["machine1"]
|
||||||
# hostnames = flake.select("nixosConfigurations.*.config.networking.hostName")
|
m1["nixpkgs"]["hostPlatform"] = "x86_64-linux"
|
||||||
|
# flake.machines["machine2"] = m1.copy()
|
||||||
|
# flake.machines["machine3"] = m1.copy()
|
||||||
|
flake.refresh()
|
||||||
|
|
||||||
|
flake_ = Flake(str(flake.path))
|
||||||
|
import os
|
||||||
|
os.environ["HOME"] = "/home/grmpf"
|
||||||
|
hostnames = flake_.select("nixosConfigurations.*.config.networking.hostName")
|
||||||
|
# assert hostnames == {"machine1": "machine1", "machine2": "machine2", "machine3": "machine3"}
|
||||||
|
assert hostnames == {"machine1": "machine1"}
|
||||||
|
|||||||
Reference in New Issue
Block a user