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