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
make-disk-image: change to be less VM-centric #24964
Conversation
@copumpkin, thanks for your PR! By analyzing the history of the files in this pull request, we identified @domenkozar, @edolstra and @obadz to be potential reviewers. |
How long does the build take on EC2 with this PR? |
Under a minute for the default Amazon image module. I'll put up some stats
later! Faster on bare metal too
…On Mon, Apr 17, 2017 at 10:21 Domen Kožar ***@***.***> wrote:
How long does the build take on EC2 with this PR?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#24964 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAAKP3NeoDQDkDM8KjVtVXDklPXmHqdKks5rw3V2gaJpZM4M-1RU>
.
|
I just had a 3 hour deploy where AMI handling was ~80min so this is highly appreciated!! |
Sorry to hear that! I hope to get this PR in a mergeable state later today,
so with any luck we'll all be fast by default very soon now :)
…On Mon, Apr 17, 2017 at 10:24 Domen Kožar ***@***.***> wrote:
I just had a 3 hour deploy where AMI handling was ~80min so this is highly
appreciated!!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#24964 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAAKP606LbGYs0GSDGZmIiWTH6mv1zi8ks5rw3Y3gaJpZM4M-1RU>
.
|
Hm, tools for cheap image builds sound like something useful for spinoffs, too… |
nixos/lib/make-disk-image.nix
Outdated
pkgs.vmTools.runInLinuxVM ( | ||
let | ||
# Copied from https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/installer/cd-dvd/channel.nix | ||
channelSources = pkgs.runCommand "nixos-${config.system.nixosVersion}" {} '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This chunk might not actually be necessary...
2037fef
to
27a49ef
Compare
Pushed a few more changes that I think take this out of WIP land. I also ran a few tests for speed in a loop just to get a sense for how this performs. On (the same across all tries) physical hardware (with VT-X etc.): Before I merged
This PR:
On EC2: I don't have exact measurements handy but my EC2 image builds were in the 25-30 minute range and are now in the 30s-1m range. |
exportReferencesGraph = [ "closure" metaClosure ]; | ||
postVM = '' | ||
${if format == "raw" then '' | ||
mv $diskImage $out/nixos.img |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks nixos/modules/virtualisation/virtualbox-image.nix which relies on $diskImage being set.
The former code had diskImage=$out/nixos.${if format == "qcow2" then "qcow2" else "img"}
in PreVM, which makes much sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! What's the best way to test that? Is there a good VM test or a nix-build invocation I can run to make sure it works?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I've been able to repro with this:
nix-build nixos/ --no-out-link -A config.system.build.virtualBoxOVA --arg configuration "{ imports = [ ./nixos/modules/virtualisation/virtualbox-image.nix ]; }"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@layus I don't think I can replicate that exact logic sensibly here, but I'll make it work for downstream consumers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I can build an OVA fine in the latest push. Takes about a minute to build on my machine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also tested that novaImage
works fine, which seems to be the only other thing that uses make-disk-image.nix
. An upcoming PR will consolidate all the other image builders (GCE, Azure, etc.) to use this script (making adjustments here to accommodate variations)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you figured everything yourself. Nice :-).
Some years ago, I tried to build a VBox image using Nix{,OS}. It took one hour to make a trivial image. Now I took me about 8min, download included. There are still three copies where one would be optimal, but it's already way faster.
27a49ef
to
9ce7d1d
Compare
nixos/lib/make-disk-image.nix
Outdated
done | ||
# Set up core system link, GRUB, etc. | ||
NIXOS_INSTALL_BOOTLOADER=1 chroot $mountPoint /nix/var/nix/profiles/system/bin/switch-to-configuration boot | ||
chroot $mountPoint /nix/var/nix/profiles/system/activate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I be calling the activation script here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As opposed to not calling activate
at all? Was the activation script called in the previous flow?
@shlevy mind taking a look? |
@copumpkin probably not until this weekend, sorry |
@volth I'd certainly be open to that, but probably not as part of this ticket, which is purely trying to refactor the implementation of the existing interface. Perhaps make a ticket talking about how you might use that? The thought of having builds not managed by Nix blows my mind so I can't imagine it 😄 |
d4516ea
to
7f8f168
Compare
It turns out I actually broke the old |
Not I, FWIW. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside from the (open?) question regarding /nix/var/nix/profiles/system/activate
, this looks good to me.
I think it's reasonable to refactor the filterFn
and other channel bits in a follow up.
The old thing didn't call |
@copumpkin Perhaps it's best to keep the
That's essentially what one of your old PRs did (which I think I contributed a bit to, IIRC), right? My memory is a little foggy here. I would think calling |
Both of those work today with this configuration but you're right, I probably don't want the activation script in here. I'll take it out for now. The EC2 boot configuration thing is what actually runs in our EC2 VM tests and those still pass after this PR :)
… On Apr 21, 2017, at 14:19, Charles Strahan ***@***.***> wrote:
@copumpkin Perhaps it's best to keep the activate part as it was, then. Also, I could be wrong, but I thought there was a use case in the context of AMIs that went something like this:
Create an image with a particular configuration
When it first boots, the activation script reads some info from the environment, and possibly pulls down a new configuration.nix, which it then switches to
That's essentially what one of your old PRs did (which I think I contributed a bit to, IIRC), right? My memory is a little foggy here.
I would think calling activate would make it difficult (or impossible) to do such first-boot setup.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I'm not really all that familiar with this code and dont' really have an opinion either way. Fine by me if it works. |
🚢 👍 |
Okay when I get back to my computer I'll remove the activation script invocation then merge. We can always revert if it's a disaster:)
… On Apr 23, 2017, at 14:19, Charles Strahan ***@***.***> wrote:
🚢 👍
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
This changes much of the make-disk-image.nix logic (and thus most NixOS image building) to use LKL to set up the target directory structure rather than a Linux VM. The only work we still do in a VM is less IO-heavy stuff that while still time-consuming, is less of the overall load. The goal is to kill more of that stuff, but that will require deeper changes to NixOS activation scripts and switch-to-configuration.pl, and I don't want to bite off too much at once.
7f8f168
to
f1708a9
Compare
Okay, removed the call to |
I'll test this shortly. Thanks! |
This changes much of the make-disk-image.nix logic (and thus most NixOS image building) to use LKL to set up the target directory structure rather than a Linux VM. The only work we still do in a VM is less IO-heavy stuff that while still time-consuming, is less of the overall load. The goal is to kill more of that stuff, but that will require deeper changes to NixOS activation scripts and switch-to-configuration.pl, and I don't want to bite off too much at once.
This is a new version of #21943, refactored to take advantage of the new
nixos-prepare-root
logic I introduce in #23026. There's still a couple of WIP things here but I wanted to get this out there to show what I've been talking about in the other PR.Motivation for this change
Building disk images with VMs is miserable in EC2 and other cloud virtualization providers, and doesn't work at all in local VMWare due to some shady nested virtualization bugs.
Things done
(nix.useSandbox on NixOS,
or option
build-use-sandbox
innix.conf
on non-NixOS)
nix-shell -p nox --run "nox-review wip"
./result/bin/
)