support flakes in vm alias

This commit is contained in:
cswimr 2025-01-28 07:44:24 -06:00
parent c07c6baeae
commit 7e7234e00a
Signed by: cswimr
GPG key ID: 0EC431A8DA8F8087

View file

@ -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}")