2024-08-02 09:13:06 -04:00
|
|
|
import logging
|
|
|
|
from typing import Optional
|
2025-03-02 00:12:08 -05:00
|
|
|
from flupdt.common import bash_wrapper
|
2024-08-02 09:13:06 -04:00
|
|
|
import re
|
|
|
|
|
2024-08-03 00:21:44 -04:00
|
|
|
drv_re = re.compile(r".*(/nix/store/.*\.drv).*")
|
2024-08-02 09:13:06 -04:00
|
|
|
|
2024-08-03 00:21:44 -04:00
|
|
|
|
|
|
|
def evaluate_output(path: str, output: str) -> Optional[str]:
|
2024-08-02 09:13:06 -04:00
|
|
|
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:
|
|
|
|
logging.warning(f"output {output} did not evaluate correctly")
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
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)
|
|
|
|
logging.debug(f"derivation evaluated to {drv}")
|