pass system when importing nixpkgs

This commit is contained in:
figsoda 2023-01-08 10:30:03 -05:00
parent c7101575e0
commit 3928ea476b
3 changed files with 12 additions and 4 deletions

View File

@ -100,6 +100,7 @@ def parse_args(args: list[str]) -> Options:
review=a.review,
format=a.format,
override_filename=a.override_filename,
system=a.system,
system_flags=["--system", a.system] if a.system else [],
)

View File

@ -53,9 +53,14 @@ class Package:
self.version_position = Position(**raw_version_position)
def eval_expression(import_path: str, attr: str, flake: bool) -> str:
def eval_expression(
import_path: str, attr: str, flake: bool, system: Optional[str]
) -> str:
system = f'"{system}"' if system else "builtins.currentSystem"
let_bindings = (
f"""inherit (builtins) currentSystem getFlake stringLength substring;
f"""inherit (builtins) getFlake stringLength substring;
currentSystem = {system};
flake = getFlake "{import_path}";
pkg = flake.packages.${{currentSystem}}.{attr} or flake.{attr};
inherit (flake) outPath;
@ -66,7 +71,8 @@ def eval_expression(import_path: str, attr: str, flake: bool) -> str:
if flake
else f"""
inputs = if (builtins.functionArgs (import {import_path})) ? overlays then {{ overlays = [ ]; }} else {{ }};
pkg = (import {import_path} inputs).{attr};
system = if (builtins.functionArgs (import {import_path})) ? system then {{ system = {system}; }} else {{ }};
pkg = (import {import_path} (inputs // system)).{attr};
sanitizePosition = x: x;"""
)
@ -107,7 +113,7 @@ in {{
def eval_attr(opts: Options) -> Package:
expr = eval_expression(opts.import_path, opts.attribute, opts.flake)
expr = eval_expression(opts.import_path, opts.attribute, opts.flake, opts.system)
cmd = [
"nix",
"eval",

View File

@ -23,4 +23,5 @@ class Options:
test: bool = False
review: bool = False
format: bool = False
system: Optional[str] = None
system_flags: List[str] = field(default_factory=list)