Skip to content

Commit

Permalink
Merge pull request nix-community#4 from teto/make_disk_image
Browse files Browse the repository at this point in the history
 Convert libvirtd to use make-disk-image
  • Loading branch information
AmineChikhaoui authored Oct 16, 2019
2 parents 8c278af + bdfa512 commit 1c29f6c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 120 deletions.
89 changes: 0 additions & 89 deletions nix/libvirtd-image.nix

This file was deleted.

38 changes: 12 additions & 26 deletions nix/libvirtd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,19 @@
with lib;

let
sz = toString config.deployment.libvirtd.baseImageSize;
base_image = import ./libvirtd-image.nix { size = sz; };
the_key = builtins.getEnv "NIXOPS_LIBVIRTD_PUBKEY";
ssh_image = pkgs.vmTools.runInLinuxVM (
pkgs.runCommand "libvirtd-ssh-image"
{ memSize = 768;
preVM =
''
mkdir $out
diskImage=$out/image
${pkgs.vmTools.qemu}/bin/qemu-img create -f qcow2 -b ${base_image}/disk.qcow2 $diskImage
'';
buildInputs = [ pkgs.utillinux ];
postVM =
''
mv $diskImage $out/disk.qcow2
'';
}
''
mkdir /mnt
mount /dev/vda1 /mnt
mkdir -p /mnt/etc/ssh/authorized_keys.d
echo '${the_key}' > /mnt/etc/ssh/authorized_keys.d/root
umount /mnt
''
);
ssh_image = import <nixpkgs/nixos/lib/make-disk-image.nix> {
name = "libvirtd-ssh-image";
format = "qcow2";
diskSize = config.deployment.libvirtd.baseImageSize * 1024;
config = config;
contents = [{
source = (pkgs.writeText "authorized_keys.d-root" the_key);
target = "/etc/ssh/authorized_keys.d/root";
}];
lib = pkgs.lib;
inherit pkgs;
};
in

{
Expand Down
6 changes: 1 addition & 5 deletions nixopsvirtd/backends/libvirtd.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,7 @@ def _prepare_storage_volume(self):
capture_stdout=True, env=newEnv).rstrip()

temp_disk_path = os.path.join(self.depl.tempdir, 'disk-{}.qcow2'.format(self.name))
shutil.copyfile(os.path.join(temp_image_path, 'disk.qcow2'), temp_disk_path)
# Rebase onto empty backing file to prevent breaking the disk image
# when the backing file gets garbage collected.
self._logged_exec(["qemu-img", "rebase", "-f", "qcow2", "-b",
"", temp_disk_path])
shutil.copyfile(os.path.join(temp_image_path, 'nixos.qcow2'), temp_disk_path)

self.logger.log("uploading disk image...")
image_info = self._get_image_info(temp_disk_path)
Expand Down

0 comments on commit 1c29f6c

Please sign in to comment.