From 825caeb63a3d01e9ce0d449f4a99d787cb3953c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 13 Sep 2023 16:01:03 +0200 Subject: [PATCH] add nix_build_machine function --- pkgs/clan-cli/clan_cli/nix.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/pkgs/clan-cli/clan_cli/nix.py b/pkgs/clan-cli/clan_cli/nix.py index a90b29b..6356256 100644 --- a/pkgs/clan-cli/clan_cli/nix.py +++ b/pkgs/clan-cli/clan_cli/nix.py @@ -1,7 +1,38 @@ +import json import os import tempfile -from .dirs import nixpkgs_flake, nixpkgs_source, unfree_nixpkgs +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() + payload = json.dumps( + dict( + clan_flake=clan_flake, + machine=machine, + attr=attr, + ) + ) + return [ + "nix", + "build", + "--impure", + "--print-out-paths", + "--expr", + f'let args = builtins.fromJSON "{payload}"; in ' + """ + let + flake = builtins.getFlake args.clan_flake; + config = flake.nixosConfigurations.${args.machine}.extendModules { + modules = [{ + clanCore.clanDir = args.clan_flake; + }]; + }; + in + flake.inputs.nixpkgs.lib.getAttrFromPath args.attr config + """, + ] def nix_eval(flags: list[str]) -> list[str]: