Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Hyperv support #36

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions nixos-x86_64.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,36 @@
"1024"
]
]
},
{
"boot_wait": "40s",
"boot_command": [
"echo http://{{.HTTPIP}}:{{.HTTPPort}} > .packer_http<enter>",
"mkdir -m 0700 .ssh<enter>",
"curl $(cat .packer_http)/install_rsa.pub > .ssh/authorized_keys<enter><wait>",
"sed -i '5ivirtualisation.hypervGuest.enable = true;' /etc/nixos/configuration.nix<enter><wait>",
"sed -i '6idocumentation.man.enable = false; documentation.enable = false;' /etc/nixos/configuration.nix<enter><wait>",
"sed -i '7iservices.nixosManual.enable = false;' /etc/nixos/configuration.nix<enter><wait>",
"nixos-rebuild switch<enter><wait>",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this line necessary? It's not used for the other targets

Copy link
Collaborator Author

@PierreR PierreR Jan 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove that line and tested ... It is actually needed because nixos has to be rebuild with virtualisation.hypervGuest.enable = true; otherwise windows never gets the IP back from the guest and the ssh callback will never fire. That means that I need the sed call after all ...

In other words, I need to rebuild the nixos guest with hypervGuest enable to have a chance to get the provisioned install script to kick in. Can you think of another way to make this work ?

For your information, even when the hyperv packer images succeeded, I have never managed to get it work with vagrant. For some reason the X server will fail to start up ...

At the end, hyperv has been a gigantic piece of wasted time on my side :-(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch, sorry to hear that. I think the best way would be to change the generation of images to be Nix-driven instead of Packer-driven. But that will take some more work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The least effort would to cave in and install VirtualBox I'm afraid. I also think that Vagrant mainly works well with VirtualBox, all the other targets are less tested.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok no problem. I don't mind closing the PR and keeping the branch for documentation purpose.

As a note, what motivates me to investigate other hypervisors is the need for nested virtualization (not supported by Virtualbox on Intel).

"systemctl start sshd<enter>"
],
"http_directory": "scripts",
"switch_name": "Devbox",
"iso_checksum_type": "sha256",
"shutdown_command": "shutdown -h now",
"ssh_private_key_file": "./scripts/install_rsa",
"ssh_port": 22,
"ssh_timeout": "600s",
"ssh_username": "root",
"type": "hyperv-iso",
"iso_url": "https://d3g5gsiof5omrk.cloudfront.net/nixos/18.09/nixos-18.09.1799.b9fa31cea0e/nixos-minimal-18.09.1799.b9fa31cea0e-x86_64-linux.iso",
"iso_checksum": "cc7c399c5fe4672383fe54cb1d648854a0d6732765fe1a61bb38b3fe3b7c6d2f",
"disk_size": 62000,
"cpu": 3,
"ram_size": 2048,
"enable_mac_spoofing": true,
"guest_additions_mode": "disable",
"enable_virtualization_extensions": false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The json code is generated by the gen_template.rb script. The new target would be declared here:

Copy link
Member

@zimbatm zimbatm Jan 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To re-generate the json run nix-shell --run "make update"

}
],
"provisioners": [
Expand Down
1 change: 1 addition & 0 deletions scripts/configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
./hardware-configuration.nix
./hardware-builder.nix
./vagrant.nix
./custom-configuration.nix
];

# Use the GRUB 2 boot loader.
Expand Down
6 changes: 6 additions & 0 deletions scripts/custom-configuration.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{ config, pkgs, ... }:

{
# Place here any custom configuration specific to your organisation (locale, ...)
# if you want it to be part of the packer base image to be used with vagrant.
}
2 changes: 2 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ mount LABEL=nixos /mnt

# Setup system
nixos-generate-config --root /mnt

curl -sf "$packer_http/vagrant.nix" > /mnt/etc/nixos/vagrant.nix
curl -sf "$packer_http/vagrant-hostname.nix" > /mnt/etc/nixos/vagrant-hostname.nix
curl -sf "$packer_http/vagrant-network.nix" > /mnt/etc/nixos/vagrant-network.nix
curl -sf "$packer_http/builders/$PACKER_BUILDER_TYPE.nix" > /mnt/etc/nixos/hardware-builder.nix
curl -sf "$packer_http/configuration.nix" > /mnt/etc/nixos/configuration.nix
curl -sf "$packer_http/custom-configuration.nix" > /mnt/etc/nixos/custom-configuration.nix

### Install ###
nixos-install
Expand Down