Skip to content

Commit

Permalink
feat(eval): opt-in support for nix-build
Browse files Browse the repository at this point in the history
Plugins might need to call this function to actually build something in the nix store.

See nix-community/nixops-vbox#28 (comment) for example.

We need a way to tell eval to do a build. Here it is.

@moduon MT-904
  • Loading branch information
yajo committed Jul 8, 2022
1 parent fc78a64 commit 8698419
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion nixops/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,21 @@ def eval(
extra_flags: List[str] = [],
# Non-propagated args
stderr: Optional[TextIO] = None,
build: bool = False,
) -> Any:

exprs: List[str] = list(networkExprs)
if not networkExpr.is_flake:
exprs.append(networkExpr.network)

base_cmd: List[str] = (
["nix-build"]
if build
else ["nix-instantiate", "--eval-only", "--json", "--strict"]
)
argv: List[str] = (
["nix-instantiate", "--eval-only", "--json", "--strict", "--show-trace"]
base_cmd
+ ["--show-trace"]
+ [os.path.join(get_expr_path(), "eval-machine-info.nix")]
+ ["-I", "nixops=" + get_expr_path()]
+ [
Expand Down Expand Up @@ -124,6 +131,8 @@ def eval(

try:
ret = subprocess.check_output(argv, stderr=stderr, text=True)
if build:
return ret.strip()
return json.loads(ret)
except OSError as e:
raise Exception("unable to run ‘nix-instantiate’: {0}".format(e))
Expand Down

0 comments on commit 8698419

Please sign in to comment.