Compare commits

..

No commits in common. "main" and "feature/uv2nix" have entirely different histories.

7 changed files with 52 additions and 64 deletions

30
flake.lock generated
View File

@ -57,11 +57,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1744174375,
"narHash": "sha256-oxI9TLgnQbQ/WL0tIwVSIooLbXq4PW1QUhf5aQmXFgk=",
"lastModified": 1742276595,
"narHash": "sha256-bsg9y3NoMGu0jgTI5XbxvzQFc9JtZB51i500WlVws80=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "ef3a956f697525883b77192cbe208233ea0f8f79",
"rev": "2b3795787eba0066a2bc8bba7362422e5713840f",
"type": "github"
},
"original": {
@ -80,11 +80,11 @@
]
},
"locked": {
"lastModified": 1742649964,
"narHash": "sha256-DwOTp7nvfi8mRfuL1escHDXabVXFGT1VlPD1JHrtrco=",
"lastModified": 1741379162,
"narHash": "sha256-srpAbmJapkaqGRE3ytf3bj4XshspVR5964OX5LfjDWc=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "dcf5072734cb576d2b0c59b2ac44f5050b5eac82",
"rev": "b5a62751225b2f62ff3147d0a334055ebadcd5cc",
"type": "github"
},
"original": {
@ -106,11 +106,11 @@
]
},
"locked": {
"lastModified": 1744284767,
"narHash": "sha256-f0Z1OqugZjvofIud0Mpr+ySTJwyYR9UO7lSxY8jRd4g=",
"lastModified": 1741647088,
"narHash": "sha256-y/Aj21rMGdE23dcFfD4lRhNMgkhIRucp+uuWLWUXv0M=",
"owner": "pyproject-nix",
"repo": "build-system-pkgs",
"rev": "38947cfda923e44ce63db057e7772f4a48b7ebbd",
"rev": "6d7eced86469cf89ed4d19d91b870163deb0dca2",
"type": "github"
},
"original": {
@ -126,11 +126,11 @@
]
},
"locked": {
"lastModified": 1743438845,
"narHash": "sha256-1GSaoubGtvsLRwoYwHjeKYq40tLwvuFFVhGrG8J9Oek=",
"lastModified": 1741648141,
"narHash": "sha256-jQEZCSCgm60NGmBg3JPu290DDhNVI1GVVEd0P8VCnME=",
"owner": "pyproject-nix",
"repo": "pyproject.nix",
"rev": "8063ec98edc459571d042a640b1c5e334ecfca1e",
"rev": "7747e5a058245c7abe033a798f818f0572d8e155",
"type": "github"
},
"original": {
@ -174,11 +174,11 @@
]
},
"locked": {
"lastModified": 1744279763,
"narHash": "sha256-0k6eJPWfI56e9WbjNFTKKYoP8YX31gXHOcKz/zeLdBs=",
"lastModified": 1742147344,
"narHash": "sha256-//dMTPMfAeUFQWkwyuFF0NBTENliZF/p1gCWln2eDHA=",
"owner": "pyproject-nix",
"repo": "uv2nix",
"rev": "2b0fbb003988891c44b01b3e556f5fac817253ed",
"rev": "3bc6e12cf559c2fd39ce6f4e5d408817e53ac648",
"type": "github"
},
"original": {

View File

@ -4,7 +4,7 @@
nixConfig = {
substituters = [
"https://cache.nixos.org/?priority=1&want-mass-query=true"
#"https://attic.nayeonie.com/nix-cache"
"https://attic.nayeonie.com/nix-cache"
"https://nix-community.cachix.org/?priority=10&want-mass-query=true"
];
trusted-substituters = [
@ -17,7 +17,6 @@
"nix-cache:trR+y5nwpQHR4hystoogubFmp97cewkjWeqqbygRQRs="
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
];
fallback = true;
};
inputs = {

View File

@ -11,7 +11,6 @@ from flupdt.common import bash_wrapper
drv_re = re.compile(r".*(/nix/store/.*\.drv).*")
OUTPUT_DIR = mkdtemp(prefix="flupdt-outputs-")
logger = logging.getLogger(__name__)
def build_output(path: str, output: str) -> str | None:
@ -21,16 +20,16 @@ def build_output(path: str, output: str) -> str | None:
:param output: flake output to be built
:returns the .drv path on success or None on failure
"""
logger.info(f"build {output}")
logger.debug(f"outputting to {OUTPUT_DIR}/{output}.nixoutput")
out = bash_wrapper(f"nix build {path}#{output} -o {OUTPUT_DIR}/{output}.nixoutput --accept-flake-config")
logger.debug("output")
logger.debug(out[0])
logger.debug("error")
logger.debug(out[1])
logger.debug("statuscode")
logger.debug(out[2])
logging.info(f"build {output}")
logging.debug(f"outputting to {OUTPUT_DIR}/{output}.nixoutput")
out = bash_wrapper(f"nix build {path}#{output} -o {OUTPUT_DIR}/{output}.nixoutput")
logging.debug("output")
logging.debug(out[0])
logging.debug("error")
logging.debug(out[1])
logging.debug("statuscode")
logging.debug(out[2])
if out[2] != 0:
logger.warning(f"output {output} did not build correctly")
logging.warning(f"output {output} did not build correctly")
return None
return ""

View File

@ -5,8 +5,6 @@ import shutil
from flupdt.common import bash_wrapper
logger = logging.getLogger(__name__)
def compare_derivations(
path_to_flake: str, path_to_pre_drv: str, path_to_post_drv: str, *, soft_failure: bool = True
@ -26,10 +24,10 @@ def compare_derivations(
)
if returncode != 0:
log_func = logger.error
log_func = logging.error
if soft_failure:
log_func = logger.warning
logger.warning(f"diff failed for {path_to_pre_drv} and {path_to_post_drv}")
log_func = logging.warning
logging.warning(f"diff failed for {path_to_pre_drv} and {path_to_post_drv}")
log_func(stderr)
return stdout

View File

@ -9,8 +9,6 @@ from flupdt.common import bash_wrapper
drv_re = re.compile(r".*(/nix/store/.*\.drv).*")
logger = logging.getLogger(__name__)
def evaluate_output(path: str, output: str) -> str | None:
"""Evaluates a given output in a flake.
@ -20,19 +18,19 @@ def evaluate_output(path: str, output: str) -> str | None:
:returns the .drv path on success or None on failure
:raises RuntimeError: evaluation succeeds but no derivation is found
"""
logger.info(f"evaluating {output}")
out = bash_wrapper(f"nix eval {path}#{output} --accept-flake-config")
logger.debug(out[0])
logger.debug(out[1])
logger.debug(out[2])
logging.info(f"evaluating {output}")
out = bash_wrapper(f"nix eval {path}#{output}")
logging.debug(out[0])
logging.debug(out[1])
logging.debug(out[2])
if out[2] != 0:
logger.warning(f"output {output} did not evaluate correctly")
logging.warning(f"output {output} did not evaluate correctly")
return None
drv_match = drv_re.match(out[0])
if drv_match is None:
out_msg = "derivation succeeded but output derivation does not contain a derivation"
raise RuntimeError(out_msg)
drv = drv_match.group(1)
logger.debug(f"derivation evaluated to {drv}")
logging.debug(f"derivation evaluated to {drv}")
return drv

View File

@ -12,7 +12,6 @@ output_regexes = [
re.compile(r"checking derivation (.*)..."),
re.compile(r"checking NixOS configuration \'(nixosConfigurations.*)\'\.\.\."),
]
logger = logging.getLogger(__name__)
def traverse_json_base(json_dict: dict[str, typing.Any], path: list[str]) -> list[str]:
@ -53,9 +52,9 @@ def get_derivations_from_check(nix_path: str, path_to_flake: str) -> list[str]:
:param path_to_flake: path to flake to be checked
:returns a list of all valid derivations in the flake
"""
flake_check = bash_wrapper(f"{nix_path} flake check --verbose --keep-going --accept-flake-config", path=path_to_flake)
flake_check = bash_wrapper(f"{nix_path} flake check --verbose --keep-going", path=path_to_flake)
if flake_check[2] != 0:
logger.warning(
logging.warning(
"nix flake check returned non-zero exit code, collecting all available outputs"
)
error_out = flake_check[1].split("\n")
@ -63,10 +62,10 @@ def get_derivations_from_check(nix_path: str, path_to_flake: str) -> list[str]:
derivations = []
for output in possible_outputs:
for r in output_regexes:
logger.debug(f"{output} {r.pattern}")
logging.debug(f"{output} {r.pattern}")
match = r.match(output)
if match is not None:
logger.debug(match.groups())
logging.debug(match.groups())
derivations += [match.groups()[0]]
return derivations
@ -83,10 +82,10 @@ def get_derivations(path_to_flake: str) -> list[str]:
if nix_path is None:
status_msg = "nix is not available in the PATH, please verify that it is installed"
raise RuntimeError(status_msg)
flake_show = bash_wrapper(f"{nix_path} flake show --json --accept-flake-path", path=path_to_flake)
flake_show = bash_wrapper(f"{nix_path} flake show --json", path=path_to_flake)
if flake_show[2] != 0:
logger.error("flake show returned non-zero exit code")
logger.warning("falling back to full evaluation via nix flake check")
logging.error("flake show returned non-zero exit code")
logging.warning("falling back to full evaluation via nix flake check")
derivations = get_derivations_from_check(nix_path, path_to_flake)
else:
flake_show_json = json.loads(flake_show[0])

View File

@ -4,7 +4,6 @@
import logging
import os
import sys
from argparse import Namespace
from pathlib import Path
@ -15,8 +14,6 @@ from flupdt.flake_diff import compare_derivations
from flupdt.flake_eval import evaluate_output
from flupdt.flake_show import get_derivations
logger = logging.getLogger(__name__)
def batch_eval(args: Namespace, flake_path: str, derivations: list[str]) -> None:
"""Bulk run evaluations or builds on a derivation set.
@ -31,14 +28,12 @@ def batch_eval(args: Namespace, flake_path: str, derivations: list[str]) -> None
if args.evaluate:
drv_map[d] = evaluate_output(flake_path, d)
if args.build:
drv_map[d] = build_output(flake_path, d)
build_output(flake_path, d)
if args.json:
with Path.open(args.json, "w+") as f:
from json import dump
dump(drv_map, f)
if any(x is None for x in drv_map.values()):
sys.exit(1)
def compare_drvs(args: Namespace) -> None:
@ -57,8 +52,8 @@ def compare_drvs(args: Namespace) -> None:
pre_json_dict = load(pre)
post_json_dict = load(post)
logger.debug(f"pre-snapshot derivations: {pre_json_dict}")
logger.debug(f"post-snapshot derivations: {post_json_dict}")
logging.debug(f"pre-snapshot derivations: {pre_json_dict}")
logging.debug(f"post-snapshot derivations: {post_json_dict}")
pre_json_keys = set(pre_json_dict.keys())
post_json_keys = set(post_json_dict.keys())
@ -69,11 +64,11 @@ def compare_drvs(args: Namespace) -> None:
missing_pre_keys = post_json_keys.difference(common_keys_to_eval)
if missing_pre_keys:
logger.warning(f"Following outputs are missing from pre-snapshot: {missing_pre_keys}")
logging.warning(f"Following outputs are missing from pre-snapshot: {missing_pre_keys}")
if missing_post_keys:
logger.warning(f"Following outputs are missing from post-snapshot: {missing_post_keys}")
logging.warning(f"Following outputs are missing from post-snapshot: {missing_post_keys}")
logger.info(f"Evaluating the following outputs for differences: {common_keys_to_eval}")
logging.info(f"Evaluating the following outputs for differences: {common_keys_to_eval}")
out_file: str = os.devnull
if args.compare_output_to_file:
@ -102,11 +97,11 @@ def build_or_eval(args: Namespace) -> None:
lambda s: s.startswith("hydraJobs"), get_derivations(flake_path)
)
derivations, hydra_jobs = list(derivations), list(hydra_jobs)
logger.info(f"derivations: {list(derivations)}")
logging.info(f"derivations: {list(derivations)}")
batch_eval(args, flake_path, derivations)
if not args.keep_hydra:
logger.info("--keep-hydra flag is not specified, removing Hydra jobs")
logging.info("--keep-hydra flag is not specified, removing Hydra jobs")
else:
batch_eval(args, flake_path, hydra_jobs)
@ -117,7 +112,7 @@ def main() -> None:
:returns: None
"""
configure_logger("INFO")
configure_logger("DEBUG")
args = parse_inputs()
if args.compare_drvs:
compare_drvs(args)