1 # nix-build '<nixpkgs/nixos>' -A config.system.build.openstackImage --arg configuration "{ imports = [ ./nixos/maintainers/scripts/openstack/openstack-image.nix ]; }"
3 { config, lib, pkgs, ... }:
5 inherit (lib) mkOption types;
7 cfg = config.openstackImage;
8 imageBootMode = if config.openstack.efi then "uefi" else "legacy-bios";
12 ../../../modules/virtualisation/openstack-config.nix
13 ] ++ (lib.optional copyChannel ../../../modules/installer/cd-dvd/channel.nix);
16 options.openstackImage = {
19 description = "The name of the generated derivation";
20 default = "nixos-openstack-image-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}";
26 description = "RAM allocation for build VM";
32 description = "The size in MB of the image";
36 type = types.enum [ "raw" "qcow2" ];
38 description = "The image format to output";
43 documentation.enable = copyChannel;
49 "tank/system/root".mount = "/";
50 "tank/system/var".mount = "/var";
51 "tank/local/nix".mount = "/nix";
52 "tank/user/home".mount = "/home";
57 system.build.openstackImage = import ../../../lib/make-single-disk-zfs-image.nix {
59 inherit (cfg) contents format name;
60 pkgs = import ../../../.. { inherit (pkgs) system; }; # ensure we use the regular qemu-kvm package
62 configFile = pkgs.writeText "configuration.nix"
64 { modulesPath, ... }: {
65 imports = [ "''${modulesPath}/virtualisation/openstack-config.nix" ];
66 openstack.zfs.enable = true;
70 includeChannel = copyChannel;
74 rootSize = cfg.sizeMB;
75 rootPoolProperties = {
80 datasets = config.openstack.zfs.datasets;
83 extension=''${rootDiskImage##*.}
84 friendlyName=$out/${cfg.name}
85 rootDisk="$friendlyName.root.$extension"
86 mv "$rootDiskImage" "$rootDisk"
88 mkdir -p $out/nix-support
89 echo "file ${cfg.format} $rootDisk" >> $out/nix-support/hydra-build-products
91 ${pkgs.jq}/bin/jq -n \
92 --arg system_label ${lib.escapeShellArg config.system.nixos.label} \
93 --arg system ${lib.escapeShellArg pkgs.stdenv.hostPlatform.system} \
94 --arg root_logical_bytes "$(${pkgs.qemu_kvm}/bin/qemu-img info --output json "$rootDisk" | ${pkgs.jq}/bin/jq '."virtual-size"')" \
95 --arg boot_mode "${imageBootMode}" \
96 --arg root "$rootDisk" \
98 | .label = $system_label
99 | .boot_mode = $boot_mode
101 | .disks.root.logical_bytes = $root_logical_bytes
102 | .disks.root.file = $root
103 ' > $out/nix-support/image-info.json