Skip to content

Instantly share code, notes, and snippets.

@evanjs
Last active June 4, 2020 18:19
Show Gist options
  • Save evanjs/253095a5eeeee686f66e1e2d2c9458f6 to your computer and use it in GitHub Desktop.
Save evanjs/253095a5eeeee686f66e1e2d2c9458f6 to your computer and use it in GitHub Desktop.
{ format ? "virtualbox"
, configuration ? ./configuration.nix
, ...
}:
let
sources = import (nix/sources.nix) {};
pkgs = import (sources.nixpkgs) {};
nixos-generators = import (pkgs.fetchFromGitHub {
owner = "evanjs";
repo = "nixos-generators";
rev = "3ccab611416e83ad171f593e4f36e85d05e39e56";
sha256 = "1mmcq35gkbgs0q8xa355qd8am4qxqd854abjyxvd708chj3kahmc";
}) {};
#nixos-generators-path = "${nixos-generators}/share/nixos-generator";
nixos-generators-path = "/home/evanjs/src/nixos-generators";
in
with pkgs;
let
confg = ./configuration.nix;
format-type = if (format == "esxi") then "virtualbox" else format;
formattedImage = pkgs.callPackage "${nixos-generators-path}/nixos-generate.nix" {
configuration = ./configuration.nix;
format-config = "${nixos-generators-path}/formats/${format-type}.nix";
};
fixedImage =
let
vmConfig = formattedImage.config.system.build;
vboxImage = vmConfig.virtualBoxOVA;
vboxName = vboxImage.name;
in
pkgs.runCommand "fix-esxi-image" {}
''
mkdir $out
tar -xvf ${vboxImage}/*.ova
ovf=$(ls -1 *.ovf)
mf=$(ls -1 *.mf)
vmdk=$(ls -1 *.vmdk)
sed 's;\(.*<vssd:VirtualSystemType>\).*\(</vssd:VirtualSystemType>\);\1vmx-14\2;;' -i nixos-20.09pre-git-x86_64-linux.ovf
sum=$(sha1sum $ovf | cut -d ' ' -f-1)
substituteInPlace $mf --replace "SHA1 ($ovf) = .*" "SHA1 ($ovf) = $sum"
tar -cvf nixos.ova $ovf $mf $vmdk
cp nixos.ova $out
'';
in
if format == "esxi" then fixedImage else formattedImage.config.system.build.${format-type}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment