From 3d071396d083237cbcc8fb5c71563293eb8d26b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 13 Sep 2023 16:40:26 +0200 Subject: [PATCH] nix_build_machine: escape json --- pkgs/clan-cli/clan_cli/nix.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/nix.py b/pkgs/clan-cli/clan_cli/nix.py index 6356256..7a29f02 100644 --- a/pkgs/clan-cli/clan_cli/nix.py +++ b/pkgs/clan-cli/clan_cli/nix.py @@ -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;