flake-update-diff/flupdt/flake_diff.py
ahuston-0 1f8d589c1b
All checks were successful
Check Nix flake / Build nix outputs (ubuntu-latest) (pull_request) Successful in 3m30s
Check flake.lock / Check health of `flake.lock` (pull_request) Successful in 14s
Check Nix flake / Perform Nix flake checks (ubuntu-latest) (pull_request) Successful in 4m30s
Check Nix formatting / Perform Nix format checks (pull_request) Successful in 2m56s
exit on failure, add per-class logging
Signed-off-by: ahuston-0 <aliceghuston@gmail.com>
2025-03-26 11:22:29 -04:00

36 lines
1.1 KiB
Python

"""Utility to diff nix derivations."""
import logging
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
) -> str:
"""Gets all derivations present in a flake.
:param path_to_flake: path to flake to be checked
:returns a list of all valid derivations in the flake
:raises RuntimeError: fails if nix is not present in the PATH
"""
nvd_path = shutil.which("nvd")
if nvd_path is None:
status_msg = "nvd is not available in the PATH, please verify that it is installed"
raise RuntimeError(status_msg)
stdout, stderr, returncode = bash_wrapper(
f"{nvd_path} diff {path_to_pre_drv} {path_to_post_drv}", path=path_to_flake
)
if returncode != 0:
log_func = logger.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(stderr)
return stdout