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

nixos/azure: improve azure module, add new maintainer scripts/examples/demo #78827

Merged
merged 7 commits into from Mar 29, 2020

Conversation

colemickens
Copy link
Member

@colemickens colemickens commented Jan 30, 2020

Motivation for this change

This is the result of various attempts to improve the Azure support in nixpkgs.
In particular:

  • add a diskSize option
  • enable boot.growPartition so that / is expanded when it boots in Azure
  • add a pair of scripts that make it easy to see how to:
    1. build a custom image and upload it as a disk, then create a re-usable image from it
    2. boot a VM from the image

Compared to previous attempts, I do not try to change any of the in-tree references to existing Azure images. In my opinion, they're all old enough and unsupported or non-functional that they should be removed. I don't think we have the necessary maintainership to try to have "release"-quality Azure images. Instead, NixOS and NixOps users should build their own (bootstrap) images.

Demo:
asciicast

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@jonringer
Copy link
Contributor

how can i test this? hard to find documentation for building images

@dali99
Copy link
Member

dali99 commented Mar 25, 2020

https://github.com/colemickens/nixcfg/tree/master/machines/azure

That's what I'm using currently to build images. I think something like ./upload-image.sh ./image-azplex.nix will build+upload an image an output the Azure Image ID.

Then ./boot-vm.sh should create a running VM booted from that image.

from a pm with @colemickens (hopefully you dont mind me posting it)

@jonringer
Copy link
Contributor

not sure if this is right, but:

[nix-shell:/home/jon/.cache/nixpkgs-review/pr-78827-1]$ nix-build -E "(import ./nixpkgs/nixos/lib/eval-config.nix { modules = [ ./nixpkgs/nixos/modules/virtualisation/azure-image.nix ({...}: { config.virtualisation.azureImage.diskSize = 4096; }) ]; }).config.system.build.azureImage"
...
WARNING: Image format was not specified for 'nixos.raw' and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the 'raw' format explicitly to remove the restrictions.
qemu-system-x86_64: CPU model 'host' requires KVM
builder for '/nix/store/4xd7jnanlllr2jl0bmsxga3nmwck23qs-azure-image.drv' failed with exit code 1
error: build of '/nix/store/4xd7jnanlllr2jl0bmsxga3nmwck23qs-azure-image.drv' failed

@jonringer
Copy link
Contributor

looks like I had CPU virtualization turned off on my BIOS.....

@colemickens
Copy link
Member Author

Thanks for testing @jonringer. Seems like you're maybe unblocked, I had meant to reply earlier...

Indeed, @dali99 shared the best instructions I have right now; that's what I use anyway. Once this change is in, I was going to extract another piece from my nixcfg and replace what is in nixos/scripts/maintainers/azure.

Copy link
Contributor

@jonringer jonringer left a comment

Choose a reason for hiding this comment

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

otherwise LGTM

nixos/modules/virtualisation/azure-image.nix Show resolved Hide resolved
nixos/modules/virtualisation/azure-image.nix Outdated Show resolved Hide resolved
@colemickens colemickens changed the title nixos/azure: add diskSize module option nixos/azure: improve azure module, add new maintainer scripts/examples/demo Mar 26, 2020
@colemickens
Copy link
Member Author

For those subscribed, I've updated this significantly. To summarize, I'll just copy the new PR body text. It now includes:

  • add a diskSize option
  • enable boot.growPartition so that / is expanded when it boots in Azure
  • add a pair of scripts that make it easy to see how to:
    1. build a custom image and upload it as a disk, then create a re-usable image from it
    2. boot a VM from the image

And the demo! https://asciinema.org/a/euXb9dIeUybE3VkstLWLbvhmp

@jonringer
Copy link
Contributor

We may want to update this page as well, but that can be done outside of this PR https://nixos.org/nixos/download.html#microsoft-azure

@colemickens
Copy link
Member Author

I left the fixes as separate commits for reviewers. LMK what you think and I can squash.

@jonringer
Copy link
Contributor

do you have issues with azcopy? Yesterday it was murdering my network, but overall using very little bandwidth

@colemickens
Copy link
Member Author

I run from my local network where I have symmetric gigabit, or from Azure, so I tend not to notice. I've only ever monitored it from an "eye ball the status bar / percentage" standpoint and it's done what I've expected.

How were you observing this? Was it starving other things? Were you monitoring its network usage?

@jonringer
Copy link
Contributor

I was trying to join a conference call, and I couldn't. And my network usage utility was showing me <100KB/s , when azcopy was showing 1MB/s+.

@colemickens
Copy link
Member Author

Hm, yeah, I'm not sure, I don't think I've seen that. It's possible that az can upload directly to the disk blob now, a bit confusing/silly that I had to use azcopy for it in the first place.

@jonringer
Copy link
Contributor

I don't see any options to use the disk command for upload, however, you can upload to blob then use blob url to create disk

        az disk create -g MyResourceGroup -n MyDisk --source
        https://vhd1234.blob.core.windows.net/vhds/osdisk1234.vhd

@colemickens
Copy link
Member Author

I spent considerable time figuring out how to avoid Azure storage accounts so, I'm unlikely to write any code that deals with storage accounts unless there's literally no other way.

@jonringer
Copy link
Contributor

Do you mind if I write it? then we can also remove the azure-storage-azcopy dependency

@colemickens
Copy link
Member Author

Here's my take. I've written the storage account management code many times and worked relatively hard to figure out the undocumented-yet-publicly-available APIs in order to remove that goop from this version of this PR - storage accounts are slow, take multiple steps to create, have annoying, asinine naming requirements, and, in this scenario, are only necessary because ... well... it's Azure.

I know this works and would prefer to merge as-is. If you want to revise it and remove azcopy, and you can make it so I can safely just look away during the storage account part (maybe even clean it up), then that seems reasonable. But I'm pretty resolved that the right fix is Azure-CLI fixing SAS Blob uploads... Azure/azure-cli#10192

@jonringer
Copy link
Contributor

Here's my take. I've written the storage account management code many times and worked relatively hard to figure out the undocumented-yet-publicly-available APIs in order to remove that goop from this version of this PR - storage accounts are slow, take multiple steps to create, have annoying, asinine naming requirements, and, in this scenario, are only necessary because ... well... it's Azure.

Agreed

@jonringer
Copy link
Contributor

I know this works and would prefer to merge as-is. If you want to revise it and remove azcopy, and you can make it so I can safely just look away during the storage account part (maybe even clean it up), then that seems reasonable. But I'm pretty resolved that the right fix is Azure-CLI fixing SAS Blob uploads... Azure/azure-cli#10192

That's fair, I'll open a new PR with a azcopyless version

@jonringer jonringer merged commit 1992768 into NixOS:master Mar 29, 2020
@colemickens
Copy link
Member Author

Thanks Jon. I'll update docs now.

@colemickens colemickens deleted the nixpkgs-azure-1 branch April 20, 2020 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants