I’ve been using NixOps to deploy a simple VM to VirtualBox via a flake:
{
description = "orchard";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-21.05";
nixops.url = "github:input-output-hk/nixops-flake";
flake-utils.url = "github:numtide/flake-utils";
};
outputs =
{ self, nixpkgs, nixops, flake-utils, ... }@inputs: {
nixopsConfigurations.default = {
inherit nixpkgs;
network = {
description = "test";
enableRollback = true;
};
vm = { config, pkgs, ... }: {
deployment = {
targetEnv = "virtualbox";
};
services.openssh.enable = true;
users.extraUsers.test = {
createHome = true;
isNormalUser = true;
extraGroups = [ "wheel" ];
group = "users";
password = "test";
};
environment.systemPackages = with pkgs; [ htop ];
};
};
} // flake-utils.lib.eachSystem [ "x86_64-darwin" ] (system:
let pkgs = nixpkgs-unstable.legacyPackages.${system};
in {
devShell = pkgs.mkShell {
nativeBuildInputs = with pkgs;
[ git git-crypt nixfmt ] ++ [ nixops.defaultPackage."${system}" ];
shellHook = ''
export NIXOPS_DEPLOYMENT=orchard
'';
NIXOPS_STATE = "./state.nixops";
};
});
}
I’m on macOS. I have not been able to deploy successfully via NixOps so far, where the SSH connection times out.
vm...................> VBoxManage: error: Could not find a registered machine named 'nixops-63d1175b-1f04-11b2-a3f8-83c086844dde-vm'
vm...................> VBoxManage: error: Details: code VBOX_E_OBJECT_NOT_FOUND (0x80bb0001), component VirtualBoxWrap, interface IVirtualBox, callee nsISupports
vm...................> VBoxManage: error: Context: "FindMachine(Bstr(VMNameOrUuid).raw(), machine.asOutParam())" at line 2733 of file VBoxManageInfo.cpp
vm...................> creating VirtualBox VM...
vm...................> Virtual machine 'nixops-63d1175b-1f04-11b2-a3f8-83c086844dde-vm' is created and registered.
vm...................> UUID: 25c7c94d-809c-4809-b4fe-f1d532f4fcc7
vm...................> Settings file: '/Users/ethan/VirtualBox VMs/nixops-63d1175b-1f04-11b2-a3f8-83c086844dde-vm/nixops-63d1175b-1f04-11b2-a3f8-83c086844dde-vm.vbox'
vm...................> creating disk ‘disk1’...
vm...................> warning: Git tree '/Users/ethan/Workspace/orchard' is dirty
vm...................> 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
vm...................> Clone medium created in format 'VDI'. UUID: db9c56bb-8ec5-4c87-bee5-26b41da8d4df
vm...................> attaching disk ‘disk1’...
vm...................> Waiting for VM "nixops-63d1175b-1f04-11b2-a3f8-83c086844dde-vm" to power on...
vm...................> VM "nixops-63d1175b-1f04-11b2-a3f8-83c086844dde-vm" has been successfully started.
vm...................> waiting for IP address........................................ 10.0.2.7
vm...................> ssh: connect to host 10.0.2.7 port 22: Operation timed out
vm...................> could not connect to ‘root@10.0.2.7’, retrying in 1 seconds...
The VM seems to boot just fine — the GUI loads to a login prompt, and the OpenSSH service starts as well. I’ve found some other questions about this online but I can’t seem to figure out how to get the initial SSH session working.