From 7e7234e00aef4dfe3f33f96f9866818a31abdb42 Mon Sep 17 00:00:00 2001 From: cswimr Date: Tue, 28 Jan 2025 07:44:24 -0600 Subject: [PATCH] support flakes in `vm` alias --- config/xonsh/aliases.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/config/xonsh/aliases.py b/config/xonsh/aliases.py index 852ceda..4806a1b 100644 --- a/config/xonsh/aliases.py +++ b/config/xonsh/aliases.py @@ -50,8 +50,14 @@ def _vm(args): vm_path = Path(f"/etc/nixos/hosts/virtual-machines/{vm_name}") if vm_path.exists(): c = colors.Colors + + if (vm_path / "flake.nix").exists(): + build_vm_args.extend(["--flake", f"{vm_path}/flake.nix#nixos"]) + elif (vm_path / "default.nix").exists(): + build_vm_args.extend(["-I", f"nixos-config={vm_path}/default.nix", "--no-flake"]) + print(f"{c.BLUE}Building virtual machine {c.YELLOW}{vm_name}{c.END}") - run(["nixos-rebuild", "build-vm", "-I", "nixos-config=./default.nix", *build_vm_args, "--no-flake"], cwd=vm_path) + run(["nixos-rebuild", "build-vm", *build_vm_args], cwd=vm_path) print(f"{c.BLUE}Starting virtual vachine {c.YELLOW}{vm_name}{c.END}") run(["./result/bin/run-nixos-vm"], cwd=vm_path) print(f"{c.BLUE}Virtual machine {c.YELLOW}{vm_name} {c.BLUE}has {c.RED}stopped.{c.END}")