Merge pull request 'nix_build_machine: escape json' (#277) from Mic92-main into main
All checks were successful
checks-impure / test (push) Successful in 6s
checks / test (push) Successful in 33s

This commit is contained in:
clan-bot 2023-09-13 14:42:42 +00:00
commit e4e888251e

View File

@ -1,26 +1,31 @@
import json
import os
import tempfile
from pathlib import Path
from .dirs import get_clan_flake_toplevel, nixpkgs_flake, nixpkgs_source, unfree_nixpkgs
def nix_build_machine(machine: str, attr: list[str]) -> list[str]:
clan_flake = get_clan_flake_toplevel()
def nix_build_machine(
machine: str, attr: list[str], flake_url: Path | None = None
) -> list[str]:
if flake_url is None:
flake_url = get_clan_flake_toplevel()
payload = json.dumps(
dict(
clan_flake=clan_flake,
clan_flake=flake_url,
machine=machine,
attr=attr,
)
)
escaped_payload = json.dumps(payload)
return [
"nix",
"build",
"--impure",
"--print-out-paths",
"--expr",
f'let args = builtins.fromJSON "{payload}"; in '
f"let args = builtins.fromJSON {escaped_payload}; in "
"""
let
flake = builtins.getFlake args.clan_flake;