2025-03-07 22:26:18 -05:00
|
|
|
"""Utility to diff nix derivations."""
|
|
|
|
|
|
|
|
import logging
|
|
|
|
import shutil
|
|
|
|
|
|
|
|
from flupdt.common import bash_wrapper
|
|
|
|
|
2025-03-26 11:22:29 -04:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2025-03-07 22:26:18 -05:00
|
|
|
|
|
|
|
def compare_derivations(
|
2025-03-08 14:45:14 -05:00
|
|
|
path_to_flake: str, path_to_pre_drv: str, path_to_post_drv: str, *, soft_failure: bool = True
|
|
|
|
) -> str:
|
2025-03-07 22:26:18 -05:00
|
|
|
"""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)
|
2025-03-08 14:45:14 -05:00
|
|
|
stdout, stderr, returncode = bash_wrapper(
|
2025-03-07 22:26:18 -05:00
|
|
|
f"{nvd_path} diff {path_to_pre_drv} {path_to_post_drv}", path=path_to_flake
|
|
|
|
)
|
|
|
|
|
2025-03-08 14:45:14 -05:00
|
|
|
if returncode != 0:
|
2025-03-26 11:22:29 -04:00
|
|
|
log_func = logger.error
|
2025-03-08 14:45:14 -05:00
|
|
|
if soft_failure:
|
2025-03-26 11:22:29 -04:00
|
|
|
log_func = logger.warning
|
|
|
|
logger.warning(f"diff failed for {path_to_pre_drv} and {path_to_post_drv}")
|
2025-03-08 14:45:14 -05:00
|
|
|
log_func(stderr)
|
2025-03-07 22:26:18 -05:00
|
|
|
|
2025-03-08 14:45:14 -05:00
|
|
|
return stdout
|