From 81b35731ebd8302f6d91f511015c2ba4e2704218 Mon Sep 17 00:00:00 2001 From: illustris Date: Tue, 29 Jul 2025 01:30:09 +0530 Subject: [PATCH 1/2] nixos/proxmox-image: add cloudImage build output Refactor proxmox image module to support both VMA and cloud-init compatible images. Extract common configuration into pveBaseConfigs and add system.build.cloudImage for cloud-init use case. --- .../modules/virtualisation/proxmox-image.nix | 141 ++++++++++-------- nixos/release.nix | 21 ++- 2 files changed, 95 insertions(+), 67 deletions(-) diff --git a/nixos/modules/virtualisation/proxmox-image.nix b/nixos/modules/virtualisation/proxmox-image.nix index d3babb785fdd..9f94738d32f6 100644 --- a/nixos/modules/virtualisation/proxmox-image.nix +++ b/nixos/modules/virtualisation/proxmox-image.nix @@ -231,6 +231,72 @@ with lib; || partitionTableType == "legacy+gpt"; hasBootPartition = partitionTableType == "efi" || partitionTableType == "hybrid"; hasNoFsPartition = partitionTableType == "hybrid" || partitionTableType == "legacy+gpt"; + postVM = + let + # Build qemu with PVE's patch that adds support for the VMA format + vma = + (pkgs.qemu_kvm.override { + alsaSupport = false; + pulseSupport = false; + sdlSupport = false; + jackSupport = false; + gtkSupport = false; + vncSupport = false; + smartcardSupport = false; + spiceSupport = false; + ncursesSupport = false; + libiscsiSupport = false; + tpmSupport = false; + numaSupport = false; + seccompSupport = false; + guestAgentSupport = false; + }).overrideAttrs + (super: rec { + # Check https://github.com/proxmox/pve-qemu/tree/master for the version + # of qemu and patch to use + version = "9.0.0"; + src = pkgs.fetchurl { + url = "https://download.qemu.org/qemu-${version}.tar.xz"; + hash = "sha256-MnCKxmww2MiSYz6paMdxwcdtWX1w3erSGg0izPOG2mk="; + }; + patches = [ + # Proxmox' VMA tool is published as a particular patch upon QEMU + "${ + pkgs.fetchFromGitHub { + owner = "proxmox"; + repo = "pve-qemu"; + rev = "14afbdd55f04d250bd679ca1ad55d3f47cd9d4c8"; + hash = "sha256-lSJQA5SHIHfxJvMLIID2drv2H43crTPMNIlIT37w9Nc="; + } + }/debian/patches/pve/0027-PVE-Backup-add-vma-backup-format-code.patch" + ]; + + buildInputs = super.buildInputs ++ [ pkgs.libuuid ]; + nativeBuildInputs = super.nativeBuildInputs ++ [ pkgs.perl ]; + + }); + in + '' + ${vma}/bin/vma create "${config.image.baseName}.vma" \ + -c ${ + cfgFile "qemu-server.conf" (cfg.qemuConf // cfg.qemuExtraConf) + }/qemu-server.conf drive-virtio0=$diskImage + rm $diskImage + ${pkgs.zstd}/bin/zstd "${config.image.baseName}.vma" + mv "${config.image.fileName}" $out/ + + mkdir -p $out/nix-support + echo "file vma $out/${config.image.fileName}" > $out/nix-support/hydra-build-products + ''; + pveBaseConfigs = { + name = "proxmox-${cfg.filenameSuffix}"; + baseName = config.image.baseName; + inherit (cfg) partitionTableType; + inherit (cfg.qemuConf) additionalSpace bootSize; + inherit (config.virtualisation) diskSize; + format = "raw"; + inherit config lib pkgs; + }; in { assertions = [ @@ -253,72 +319,15 @@ with lib; ]; image.baseName = lib.mkDefault "vzdump-qemu-${cfg.filenameSuffix}"; image.extension = "vma.zst"; - system.build.image = config.system.build.VMA; - system.build.VMA = import ../../lib/make-disk-image.nix { - name = "proxmox-${cfg.filenameSuffix}"; - baseName = config.image.baseName; - inherit (cfg) partitionTableType; - postVM = - let - # Build qemu with PVE's patch that adds support for the VMA format - vma = - (pkgs.qemu_kvm.override { - alsaSupport = false; - pulseSupport = false; - sdlSupport = false; - jackSupport = false; - gtkSupport = false; - vncSupport = false; - smartcardSupport = false; - spiceSupport = false; - ncursesSupport = false; - libiscsiSupport = false; - tpmSupport = false; - numaSupport = false; - seccompSupport = false; - guestAgentSupport = false; - }).overrideAttrs - (super: rec { - # Check https://github.com/proxmox/pve-qemu/tree/master for the version - # of qemu and patch to use - version = "9.0.0"; - src = pkgs.fetchurl { - url = "https://download.qemu.org/qemu-${version}.tar.xz"; - hash = "sha256-MnCKxmww2MiSYz6paMdxwcdtWX1w3erSGg0izPOG2mk="; - }; - patches = [ - # Proxmox' VMA tool is published as a particular patch upon QEMU - "${ - pkgs.fetchFromGitHub { - owner = "proxmox"; - repo = "pve-qemu"; - rev = "14afbdd55f04d250bd679ca1ad55d3f47cd9d4c8"; - hash = "sha256-lSJQA5SHIHfxJvMLIID2drv2H43crTPMNIlIT37w9Nc="; - } - }/debian/patches/pve/0027-PVE-Backup-add-vma-backup-format-code.patch" - ]; - - buildInputs = super.buildInputs ++ [ pkgs.libuuid ]; - nativeBuildInputs = super.nativeBuildInputs ++ [ pkgs.perl ]; - - }); - in - '' - ${vma}/bin/vma create "${config.image.baseName}.vma" \ - -c ${ - cfgFile "qemu-server.conf" (cfg.qemuConf // cfg.qemuExtraConf) - }/qemu-server.conf drive-virtio0=$diskImage - rm $diskImage - ${pkgs.zstd}/bin/zstd "${config.image.baseName}.vma" - mv "${config.image.fileName}" $out/ - - mkdir -p $out/nix-support - echo "file vma $out/${config.image.fileName}" > $out/nix-support/hydra-build-products - ''; - inherit (cfg.qemuConf) additionalSpace bootSize; - inherit (config.virtualisation) diskSize; - format = "raw"; - inherit config lib pkgs; + system.build = { + cloudImage = import ../../lib/make-disk-image.nix pveBaseConfigs; + VMA = import ../../lib/make-disk-image.nix ( + pveBaseConfigs + // { + inherit postVM; + } + ); + image = config.system.build.VMA; }; boot = { diff --git a/nixos/release.nix b/nixos/release.nix index 3bcacf1e471c..ad5df8e41573 100644 --- a/nixos/release.nix +++ b/nixos/release.nix @@ -274,7 +274,7 @@ rec { ); # KVM image for proxmox in VMA format - proxmoxImage = forMatchingSystems [ "x86_64-linux" ] ( + proxmoxVMA = forMatchingSystems [ "x86_64-linux" ] ( system: with import ./.. { inherit system; }; @@ -288,6 +288,25 @@ rec { ) ); + # Keeping the old name for compatibility + proxmoxImage = proxmoxVMA; + + # cloud-init image compatible with instructions given here: + # https://pve.proxmox.com/wiki/Cloud-Init_Support + proxmoxCloudImage = forMatchingSystems [ "x86_64-linux" ] ( + system: + with import ./.. { inherit system; }; + + hydraJob ( + (import lib/eval-config.nix { + inherit system; + modules = [ + ./modules/virtualisation/proxmox-image.nix + ]; + }).config.system.build.cloudImage + ) + ); + # LXC tarball for proxmox proxmoxLXC = forMatchingSystems [ "x86_64-linux" ] ( system: From 4b4b4f9423fe09812513877661443ee6934adbac Mon Sep 17 00:00:00 2001 From: illustris Date: Sun, 3 Aug 2025 05:02:20 +0530 Subject: [PATCH 2/2] nixos/proxmox-image: make filename consistent with package name --- nixos/modules/virtualisation/proxmox-image.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/modules/virtualisation/proxmox-image.nix b/nixos/modules/virtualisation/proxmox-image.nix index 9f94738d32f6..a0aea2a321d1 100644 --- a/nixos/modules/virtualisation/proxmox-image.nix +++ b/nixos/modules/virtualisation/proxmox-image.nix @@ -289,7 +289,7 @@ with lib; echo "file vma $out/${config.image.fileName}" > $out/nix-support/hydra-build-products ''; pveBaseConfigs = { - name = "proxmox-${cfg.filenameSuffix}"; + name = config.image.baseName; baseName = config.image.baseName; inherit (cfg) partitionTableType; inherit (cfg.qemuConf) additionalSpace bootSize;