1 # nix-build '<nixpkgs/nixos>' -A config.system.build.openstackImage --arg configuration "{ imports = [ ./nixos/maintainers/scripts/openstack/openstack-image.nix ]; }"
10 inherit (lib) mkOption types;
12 cfg = config.openstackImage;
13 imageBootMode = if config.openstack.efi then "uefi" else "legacy-bios";
17 ../../../modules/virtualisation/openstack-config.nix
18 ../../../modules/virtualisation/disk-size-option.nix
19 (lib.mkRenamedOptionModuleWith {
30 ] ++ (lib.optional copyChannel ../../../modules/installer/cd-dvd/channel.nix);
32 options.openstackImage = {
35 description = "The name of the generated derivation";
36 default = "nixos-openstack-image-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}";
42 description = "RAM allocation for build VM";
51 description = "The image format to output";
56 documentation.enable = copyChannel;
62 "tank/system/root".mount = "/";
63 "tank/system/var".mount = "/var";
64 "tank/local/nix".mount = "/nix";
65 "tank/user/home".mount = "/home";
70 # Use a priority just below mkOptionDefault (1500) instead of lib.mkDefault
71 # to avoid breaking existing configs using that.
72 virtualisation.diskSize = lib.mkOverride 1490 (8 * 1024);
73 virtualisation.diskSizeAutoSupported = false;
75 system.build.openstackImage = import ../../../lib/make-single-disk-zfs-image.nix {
77 inherit (cfg) contents format name;
78 pkgs = import ../../../.. { inherit (pkgs) system; }; # ensure we use the regular qemu-kvm package
80 configFile = pkgs.writeText "configuration.nix" ''
81 { modulesPath, ... }: {
82 imports = [ "''${modulesPath}/virtualisation/openstack-config.nix" ];
83 openstack.zfs.enable = true;
87 includeChannel = copyChannel;
91 rootSize = config.virtualisation.diskSize;
92 rootPoolProperties = {
97 datasets = config.openstack.zfs.datasets;
100 extension=''${rootDiskImage##*.}
101 friendlyName=$out/${cfg.name}
102 rootDisk="$friendlyName.root.$extension"
103 mv "$rootDiskImage" "$rootDisk"
105 mkdir -p $out/nix-support
106 echo "file ${cfg.format} $rootDisk" >> $out/nix-support/hydra-build-products
108 ${pkgs.jq}/bin/jq -n \
109 --arg system_label ${lib.escapeShellArg config.system.nixos.label} \
110 --arg system ${lib.escapeShellArg pkgs.stdenv.hostPlatform.system} \
111 --arg root_logical_bytes "$(${pkgs.qemu_kvm}/bin/qemu-img info --output json "$rootDisk" | ${pkgs.jq}/bin/jq '."virtual-size"')" \
112 --arg boot_mode "${imageBootMode}" \
113 --arg root "$rootDisk" \
115 | .label = $system_label
116 | .boot_mode = $boot_mode
118 | .disks.root.logical_bytes = $root_logical_bytes
119 | .disks.root.file = $root
120 ' > $out/nix-support/image-info.json