image/images: Adapt remaining images to system.build.image & normalized filenames, (#359345)

This commit is contained in:
Thiago Kenji Okada
2025-01-05 20:28:23 +00:00
committed by GitHub
12 changed files with 232 additions and 65 deletions

View File

@@ -20,6 +20,7 @@ in
imports = [ imports = [
../../../modules/virtualisation/amazon-image.nix ../../../modules/virtualisation/amazon-image.nix
../../../modules/virtualisation/disk-size-option.nix ../../../modules/virtualisation/disk-size-option.nix
../../../modules/image/file-options.nix
(lib.mkRenamedOptionModuleWith { (lib.mkRenamedOptionModuleWith {
sinceRelease = 2411; sinceRelease = 2411;
from = [ from = [
@@ -31,6 +32,17 @@ in
"diskSize" "diskSize"
]; ];
}) })
(lib.mkRenamedOptionModuleWith {
sinceRelease = 2505;
from = [
"amazonImage"
"name"
];
to = [
"image"
"baseName"
];
})
]; ];
# Amazon recommends setting this to the highest possible value for a good EBS # Amazon recommends setting this to the highest possible value for a good EBS
@@ -44,12 +56,6 @@ in
[ "nvme_core.io_timeout=${timeout}" ]; [ "nvme_core.io_timeout=${timeout}" ];
options.amazonImage = { options.amazonImage = {
name = mkOption {
type = types.str;
description = "The name of the generated derivation";
default = "nixos-amazon-image-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}";
};
contents = mkOption { contents = mkOption {
example = literalExpression '' example = literalExpression ''
[ { source = pkgs.memtest86 + "/memtest.bin"; [ { source = pkgs.memtest86 + "/memtest.bin";
@@ -80,6 +86,10 @@ in
config.virtualisation.diskSize = lib.mkOverride 1490 (3 * 1024); config.virtualisation.diskSize = lib.mkOverride 1490 (3 * 1024);
config.virtualisation.diskSizeAutoSupported = !config.ec2.zfs.enable; config.virtualisation.diskSizeAutoSupported = !config.ec2.zfs.enable;
config.system.nixos.tags = [ "amazon" ];
config.system.build.image = config.system.build.amazonImage;
config.image.extension = cfg.format;
config.system.build.amazonImage = config.system.build.amazonImage =
let let
configFile = pkgs.writeText "configuration.nix" '' configFile = pkgs.writeText "configuration.nix" ''
@@ -102,7 +112,8 @@ in
configFile configFile
pkgs pkgs
; ;
inherit (cfg) contents format name; inherit (cfg) contents format;
name = config.image.baseName;
includeChannel = true; includeChannel = true;
@@ -118,7 +129,7 @@ in
postVM = '' postVM = ''
extension=''${rootDiskImage##*.} extension=''${rootDiskImage##*.}
friendlyName=$out/${cfg.name} friendlyName=$out/${config.image.baseName}
rootDisk="$friendlyName.root.$extension" rootDisk="$friendlyName.root.$extension"
bootDisk="$friendlyName.boot.$extension" bootDisk="$friendlyName.boot.$extension"
mv "$rootDiskImage" "$rootDisk" mv "$rootDiskImage" "$rootDisk"
@@ -156,7 +167,9 @@ in
pkgs pkgs
; ;
inherit (cfg) contents format name; inherit (cfg) contents format;
inherit (config.image) baseName;
name = config.image.baseName;
fsType = "ext4"; fsType = "ext4";
partitionTableType = if config.ec2.efi then "efi" else "legacy+gpt"; partitionTableType = if config.ec2.efi then "efi" else "legacy+gpt";
@@ -164,11 +177,6 @@ in
inherit (config.virtualisation) diskSize; inherit (config.virtualisation) diskSize;
postVM = '' postVM = ''
extension=''${diskImage##*.}
friendlyName=$out/${cfg.name}.$extension
mv "$diskImage" "$friendlyName"
diskImage=$friendlyName
mkdir -p $out/nix-support mkdir -p $out/nix-support
echo "file ${cfg.format} $diskImage" >> $out/nix-support/hydra-build-products echo "file ${cfg.format} $diskImage" >> $out/nix-support/hydra-build-products

View File

@@ -16,6 +16,7 @@ in
imports = [ imports = [
../../../modules/virtualisation/openstack-config.nix ../../../modules/virtualisation/openstack-config.nix
../../../modules/virtualisation/disk-size-option.nix ../../../modules/virtualisation/disk-size-option.nix
../../../modules/image/file-options.nix
(lib.mkRenamedOptionModuleWith { (lib.mkRenamedOptionModuleWith {
sinceRelease = 2411; sinceRelease = 2411;
from = [ from = [
@@ -27,15 +28,21 @@ in
"diskSize" "diskSize"
]; ];
}) })
(lib.mkRenamedOptionModuleWith {
sinceRelease = 2505;
from = [
"openstackImage"
"name"
];
to = [
"image"
"baseName"
];
})
] ++ (lib.optional copyChannel ../../../modules/installer/cd-dvd/channel.nix); ] ++ (lib.optional copyChannel ../../../modules/installer/cd-dvd/channel.nix);
options.openstackImage = { options.openstackImage = {
name = mkOption {
type = types.str;
description = "The name of the generated derivation";
default = "nixos-openstack-image-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}";
};
ramMB = mkOption { ramMB = mkOption {
type = types.int; type = types.int;
default = (3 * 1024); default = (3 * 1024);
@@ -72,9 +79,16 @@ in
virtualisation.diskSize = lib.mkOverride 1490 (8 * 1024); virtualisation.diskSize = lib.mkOverride 1490 (8 * 1024);
virtualisation.diskSizeAutoSupported = false; virtualisation.diskSizeAutoSupported = false;
image.extension = cfg.format;
system.nixos.tags = [
"openstack"
"zfs"
];
system.build.image = config.system.build.openstackImage;
system.build.openstackImage = import ../../../lib/make-single-disk-zfs-image.nix { system.build.openstackImage = import ../../../lib/make-single-disk-zfs-image.nix {
inherit lib config; inherit lib config;
inherit (cfg) contents format name; inherit (cfg) contents format;
name = config.image.baseName;
pkgs = import ../../../.. { inherit (pkgs) system; }; # ensure we use the regular qemu-kvm package pkgs = import ../../../.. { inherit (pkgs) system; }; # ensure we use the regular qemu-kvm package
configFile = pkgs.writeText "configuration.nix" '' configFile = pkgs.writeText "configuration.nix" ''
@@ -98,7 +112,7 @@ in
postVM = '' postVM = ''
extension=''${rootDiskImage##*.} extension=''${rootDiskImage##*.}
friendlyName=$out/${cfg.name} friendlyName=$out/${config.image.baseName}
rootDisk="$friendlyName.root.$extension" rootDisk="$friendlyName.root.$extension"
mv "$rootDiskImage" "$rootDisk" mv "$rootDiskImage" "$rootDisk"

View File

@@ -3,19 +3,24 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
let let
copyChannel = true; copyChannel = true;
format = "qcow2";
in in
{ {
imports = [ imports = [
../../../modules/virtualisation/openstack-config.nix ../../../modules/virtualisation/openstack-config.nix
../../../modules/image/file-options.nix
] ++ (lib.optional copyChannel ../../../modules/installer/cd-dvd/channel.nix); ] ++ (lib.optional copyChannel ../../../modules/installer/cd-dvd/channel.nix);
documentation.enable = copyChannel; documentation.enable = copyChannel;
image.extension = format;
system.nixos.tags = [ "openstack" ];
system.build.image = config.system.build.openstackImage;
system.build.openstackImage = import ../../../lib/make-disk-image.nix { system.build.openstackImage = import ../../../lib/make-disk-image.nix {
inherit lib config copyChannel; inherit lib config copyChannel format;
inherit (config.image) baseName;
additionalSpace = "1024M"; additionalSpace = "1024M";
pkgs = import ../../../.. { inherit (pkgs) system; }; # ensure we use the regular qemu-kvm package pkgs = import ../../../.. { inherit (pkgs) system; }; # ensure we use the regular qemu-kvm package
format = "qcow2";
configFile = pkgs.writeText "configuration.nix" configFile = pkgs.writeText "configuration.nix"
'' ''
{ {

View File

@@ -9,6 +9,7 @@ let
inherit (lib) types; inherit (lib) types;
imageModules = { imageModules = {
amazon = [ ../../maintainers/scripts/ec2/amazon-image.nix ];
azure = [ ../virtualisation/azure-image.nix ]; azure = [ ../virtualisation/azure-image.nix ];
digital-ocean = [ ../virtualisation/digital-ocean-image.nix ]; digital-ocean = [ ../virtualisation/digital-ocean-image.nix ];
google-compute = [ ../virtualisation/google-compute-image.nix ]; google-compute = [ ../virtualisation/google-compute-image.nix ];
@@ -17,11 +18,45 @@ let
lxc = [ ../virtualisation/lxc-container.nix ]; lxc = [ ../virtualisation/lxc-container.nix ];
lxc-metadata = [ ../virtualisation/lxc-image-metadata.nix ]; lxc-metadata = [ ../virtualisation/lxc-image-metadata.nix ];
oci = [ ../virtualisation/oci-image.nix ]; oci = [ ../virtualisation/oci-image.nix ];
openstack = [ ../../maintainers/scripts/openstack/openstack-image.nix ];
openstack-zfs = [ ../../maintainers/scripts/openstack/openstack-image-zfs.nix ];
proxmox = [ ../virtualisation/proxmox-image.nix ]; proxmox = [ ../virtualisation/proxmox-image.nix ];
proxmox-lxc = [ ../virtualisation/proxmox-lxc.nix ];
qemu-efi = [ ../virtualisation/disk-image.nix ];
qemu = [
../virtualisation/disk-image.nix
{
image.efiSupport = false;
}
];
raw-efi = [
../virtualisation/disk-image.nix
{
image.format = "raw";
}
];
raw = [
../virtualisation/disk-image.nix
{
image.format = "raw";
image.efiSupport = false;
}
];
kubevirt = [ ../virtualisation/kubevirt.nix ]; kubevirt = [ ../virtualisation/kubevirt.nix ];
vagrant-virtualbox = [ ../virtualisation/vagrant-virtualbox-image.nix ]; vagrant-virtualbox = [ ../virtualisation/vagrant-virtualbox-image.nix ];
virtualbox = [ ../virtualisation/virtualbox-image.nix ]; virtualbox = [ ../virtualisation/virtualbox-image.nix ];
vmware = [ ../virtualisation/vmware-image.nix ]; vmware = [ ../virtualisation/vmware-image.nix ];
iso = [ ../installer/cd-dvd/iso-image.nix ];
iso-installer = [ ../installer/cd-dvd/installation-cd-base.nix ];
sd-card = [
(
let
module = ../. + "/installer/sd-card/sd-image-${pkgs.targetPlatform.linuxArch}.nix";
in
if builtins.pathExists module then module else throw "The module ${module} does not exist."
)
];
kexec = [ ../installer/netboot/netboot-minimal.nix ];
}; };
imageConfigs = lib.mapAttrs ( imageConfigs = lib.mapAttrs (
name: modules: name: modules:

View File

@@ -15,9 +15,6 @@
# Adds terminus_font for people with HiDPI displays # Adds terminus_font for people with HiDPI displays
console.packages = options.console.packages.default ++ [ pkgs.terminus_font ]; console.packages = options.console.packages.default ++ [ pkgs.terminus_font ];
# ISO naming.
isoImage.isoName = "${config.isoImage.isoBaseName}-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}.iso";
# EFI booting # EFI booting
isoImage.makeEfiBootable = true; isoImage.makeEfiBootable = true;

View File

@@ -476,24 +476,34 @@ let
in in
{ {
imports = [
(lib.mkRenamedOptionModuleWith {
sinceRelease = 2505;
from = [
"isoImage"
"isoBaseName"
];
to = [
"image"
"baseName"
];
})
(lib.mkRenamedOptionModuleWith {
sinceRelease = 2505;
from = [
"isoImage"
"isoName"
];
to = [
"image"
"fileName"
];
})
../../image/file-options.nix
];
options = { options = {
isoImage.isoName = lib.mkOption {
default = "${config.isoImage.isoBaseName}.iso";
type = lib.types.str;
description = ''
Name of the generated ISO image file.
'';
};
isoImage.isoBaseName = lib.mkOption {
default = config.system.nixos.distroId;
type = lib.types.str;
description = ''
Prefix of the name of the generated ISO image file.
'';
};
isoImage.compressImage = lib.mkOption { isoImage.compressImage = lib.mkOption {
default = false; default = false;
type = lib.types.bool; type = lib.types.bool;
@@ -858,8 +868,12 @@ in
boot.loader.timeout = 10; boot.loader.timeout = 10;
# Create the ISO image. # Create the ISO image.
image.extension = if config.isoImage.compressImage then "iso.zst" else "iso";
image.filePath = "iso/${config.image.fileName}";
system.build.image = config.system.build.isoImage;
system.build.isoImage = pkgs.callPackage ../../../lib/make-iso9660-image.nix ({ system.build.isoImage = pkgs.callPackage ../../../lib/make-iso9660-image.nix ({
inherit (config.isoImage) isoName compressImage volumeID contents; inherit (config.isoImage) compressImage volumeID contents;
isoName = "${config.image.baseName}.iso";
bootable = config.isoImage.makeBiosBootable; bootable = config.isoImage.makeBiosBootable;
bootImage = "/isolinux/isolinux.bin"; bootImage = "/isolinux/isolinux.bin";
syslinux = if config.isoImage.makeBiosBootable then pkgs.syslinux else null; syslinux = if config.isoImage.makeBiosBootable then pkgs.syslinux else null;

View File

@@ -1,11 +1,15 @@
# This module creates netboot media containing the given NixOS # This module creates netboot media containing the given NixOS
# configuration. # configuration.
{ config, lib, pkgs, ... }: { config, lib, pkgs, modulesPath, ... }:
with lib; with lib;
{ {
imports = [
../../image/file-options.nix
];
options = { options = {
netboot.squashfsCompression = mkOption { netboot.squashfsCompression = mkOption {
@@ -129,6 +133,21 @@ with lib;
} }
]; ];
image.extension = "tar.xz";
image.filePath = "tarball/${config.image.fileName}";
system.nixos.tags = [ "kexec" ];
system.build.image = config.system.build.kexecTarball;
system.build.kexecTarball = pkgs.callPackage "${toString modulesPath}/../lib/make-system-tarball.nix" {
fileName = config.image.baseName;
storeContents = [
{
object = config.system.build.kexecScript;
symlink = "/kexec_nixos";
}
];
contents = [];
};
boot.loader.timeout = 10; boot.loader.timeout = 10;
boot.postBootCommands = '' boot.postBootCommands = ''

View File

@@ -29,23 +29,33 @@ in
imports = [ imports = [
(mkRemovedOptionModule [ "sdImage" "bootPartitionID" ] "The FAT partition for SD image now only holds the Raspberry Pi firmware files. Use firmwarePartitionID to configure that partition's ID.") (mkRemovedOptionModule [ "sdImage" "bootPartitionID" ] "The FAT partition for SD image now only holds the Raspberry Pi firmware files. Use firmwarePartitionID to configure that partition's ID.")
(mkRemovedOptionModule [ "sdImage" "bootSize" ] "The boot files for SD image have been moved to the main ext4 partition. The FAT partition now only holds the Raspberry Pi firmware files. Changing its size may not be required.") (mkRemovedOptionModule [ "sdImage" "bootSize" ] "The boot files for SD image have been moved to the main ext4 partition. The FAT partition now only holds the Raspberry Pi firmware files. Changing its size may not be required.")
(lib.mkRenamedOptionModuleWith {
sinceRelease = 2505;
from = [
"sdImage"
"imageBaseName"
];
to = [
"image"
"baseName"
];
})
(lib.mkRenamedOptionModuleWith {
sinceRelease = 2505;
from = [
"sdImage"
"imageName"
];
to = [
"image"
"fileName"
];
})
../../profiles/all-hardware.nix
../../image/file-options.nix
]; ];
options.sdImage = { options.sdImage = {
imageName = mkOption {
default = "${config.sdImage.imageBaseName}-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}.img";
description = ''
Name of the generated image file.
'';
};
imageBaseName = mkOption {
default = "nixos-sd-image";
description = ''
Prefix of the name of the generated image file.
'';
};
storePaths = mkOption { storePaths = mkOption {
type = with types; listOf package; type = with types; listOf package;
example = literalExpression "[ pkgs.stdenv ]"; example = literalExpression "[ pkgs.stdenv ]";
@@ -180,18 +190,22 @@ in
sdImage.storePaths = [ config.system.build.toplevel ]; sdImage.storePaths = [ config.system.build.toplevel ];
image.extension = if config.sdImage.compressImage then "img.zst" else "img";
image.filePath = "sd-card/${config.image.fileName}";
system.nixos.tags = [ "sd-card" ];
system.build.image = config.system.build.sdImage;
system.build.sdImage = pkgs.callPackage ({ stdenv, dosfstools, e2fsprogs, system.build.sdImage = pkgs.callPackage ({ stdenv, dosfstools, e2fsprogs,
mtools, libfaketime, util-linux, zstd }: stdenv.mkDerivation { mtools, libfaketime, util-linux, zstd }: stdenv.mkDerivation {
name = config.sdImage.imageName; name = config.image.fileName;
nativeBuildInputs = [ dosfstools e2fsprogs libfaketime mtools util-linux ] nativeBuildInputs = [ dosfstools e2fsprogs libfaketime mtools util-linux ]
++ lib.optional config.sdImage.compressImage zstd; ++ lib.optional config.sdImage.compressImage zstd;
inherit (config.sdImage) imageName compressImage; inherit (config.sdImage) compressImage;
buildCommand = '' buildCommand = ''
mkdir -p $out/nix-support $out/sd-image mkdir -p $out/nix-support $out/sd-image
export img=$out/sd-image/${config.sdImage.imageName} export img=$out/sd-image/${config.image.baseName}.img
echo "${pkgs.stdenv.buildPlatform.system}" > $out/nix-support/system echo "${pkgs.stdenv.buildPlatform.system}" > $out/nix-support/system
if test -n "$compressImage"; then if test -n "$compressImage"; then

View File

@@ -0,0 +1,61 @@
{
config,
lib,
pkgs,
...
}:
let
cfg = config.image;
in
{
imports = [
./disk-size-option.nix
../image/file-options.nix
];
options.image = {
format = lib.mkOption {
description = "Format of the disk image to generate: raw or qcow2";
type = lib.types.enum [
"raw"
"qcow2"
];
default = "qcow2";
};
efiSupport = lib.mkOption {
description = "Whether the disk image should support EFI boot or legacy boot";
type = lib.types.bool;
default = true;
};
};
config = {
boot.loader.grub = lib.mkIf (!cfg.efiSupport) {
enable = lib.mkOptionDefault true;
devices = lib.mkDefault [ "/dev/vda" ];
};
boot.loader.systemd-boot.enable = lib.mkDefault cfg.efiSupport;
boot.growPartition = lib.mkDefault true;
fileSystems = {
"/" = {
device = "/dev/disk/by-label/nixos";
autoResize = true;
fsType = "ext4";
};
"/boot" = lib.mkIf (cfg.efiSupport) {
device = "/dev/disk/by-label/ESP";
fsType = "vfat";
};
};
system.nixos.tags = [ cfg.format ] ++ lib.optionals cfg.efiSupport [ "efi" ];
image.extension = cfg.format;
system.build.image = import ../../lib/make-disk-image.nix {
inherit lib config pkgs;
inherit (config.virtualisation) diskSize;
inherit (cfg) baseName format;
partitionTableType = if cfg.efiSupport then "efi" else "legacy";
};
};
}

View File

@@ -62,7 +62,7 @@ let
hydraJob ((import lib/eval-config.nix { hydraJob ((import lib/eval-config.nix {
inherit system; inherit system;
modules = makeModules module { modules = makeModules module {
isoImage.isoBaseName = "nixos-${type}"; image.baseName = "nixos-${type}";
}; };
}).config.system.build.isoImage); }).config.system.build.isoImage);

View File

@@ -55,7 +55,7 @@ let
} }
]; ];
}).config; }).config;
image = "${imageCfg.system.build.amazonImage}/${imageCfg.amazonImage.name}.qcow2"; image = "${imageCfg.system.build.amazonImage}/${imageCfg.image.imageFile}";
sshKeys = import ./ssh-keys.nix pkgs; sshKeys = import ./ssh-keys.nix pkgs;
snakeOilPrivateKey = sshKeys.snakeOilPrivateKey.text; snakeOilPrivateKey = sshKeys.snakeOilPrivateKey.text;

View File

@@ -7,7 +7,7 @@ let
config = (import ../../../../nixos/lib/eval-config.nix { config = (import ../../../../nixos/lib/eval-config.nix {
inherit system; inherit system;
modules = [ module { isoImage.isoBaseName = isoBaseName; } ] ++ extraModules; modules = [ module { image.baseName = isoBaseName; } ] ++ extraModules;
}).config; }).config;
in in