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

Changed files
+232 -65
nixos
maintainers
modules
image
installer
virtualisation
tests
pkgs
desktops
+22 -14
nixos/maintainers/scripts/ec2/amazon-image.nix
···
imports = [
../../../modules/virtualisation/amazon-image.nix
../../../modules/virtualisation/disk-size-option.nix
(lib.mkRenamedOptionModuleWith {
sinceRelease = 2411;
from = [
···
"diskSize"
];
})
];
# Amazon recommends setting this to the highest possible value for a good EBS
···
[ "nvme_core.io_timeout=${timeout}" ];
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 {
example = literalExpression ''
[ { source = pkgs.memtest86 + "/memtest.bin";
···
config.virtualisation.diskSize = lib.mkOverride 1490 (3 * 1024);
config.virtualisation.diskSizeAutoSupported = !config.ec2.zfs.enable;
config.system.build.amazonImage =
let
configFile = pkgs.writeText "configuration.nix" ''
···
configFile
pkgs
;
-
inherit (cfg) contents format name;
includeChannel = true;
···
postVM = ''
extension=''${rootDiskImage##*.}
-
friendlyName=$out/${cfg.name}
rootDisk="$friendlyName.root.$extension"
bootDisk="$friendlyName.boot.$extension"
mv "$rootDiskImage" "$rootDisk"
···
pkgs
;
-
inherit (cfg) contents format name;
fsType = "ext4";
partitionTableType = if config.ec2.efi then "efi" else "legacy+gpt";
···
inherit (config.virtualisation) diskSize;
postVM = ''
-
extension=''${diskImage##*.}
-
friendlyName=$out/${cfg.name}.$extension
-
mv "$diskImage" "$friendlyName"
-
diskImage=$friendlyName
-
mkdir -p $out/nix-support
echo "file ${cfg.format} $diskImage" >> $out/nix-support/hydra-build-products
···
imports = [
../../../modules/virtualisation/amazon-image.nix
../../../modules/virtualisation/disk-size-option.nix
+
../../../modules/image/file-options.nix
(lib.mkRenamedOptionModuleWith {
sinceRelease = 2411;
from = [
···
"diskSize"
];
})
+
(lib.mkRenamedOptionModuleWith {
+
sinceRelease = 2505;
+
from = [
+
"amazonImage"
+
"name"
+
];
+
to = [
+
"image"
+
"baseName"
+
];
+
})
];
# Amazon recommends setting this to the highest possible value for a good EBS
···
[ "nvme_core.io_timeout=${timeout}" ];
options.amazonImage = {
contents = mkOption {
example = literalExpression ''
[ { source = pkgs.memtest86 + "/memtest.bin";
···
config.virtualisation.diskSize = lib.mkOverride 1490 (3 * 1024);
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 =
let
configFile = pkgs.writeText "configuration.nix" ''
···
configFile
pkgs
;
+
inherit (cfg) contents format;
+
name = config.image.baseName;
includeChannel = true;
···
postVM = ''
extension=''${rootDiskImage##*.}
+
friendlyName=$out/${config.image.baseName}
rootDisk="$friendlyName.root.$extension"
bootDisk="$friendlyName.boot.$extension"
mv "$rootDiskImage" "$rootDisk"
···
pkgs
;
+
inherit (cfg) contents format;
+
inherit (config.image) baseName;
+
name = config.image.baseName;
fsType = "ext4";
partitionTableType = if config.ec2.efi then "efi" else "legacy+gpt";
···
inherit (config.virtualisation) diskSize;
postVM = ''
mkdir -p $out/nix-support
echo "file ${cfg.format} $diskImage" >> $out/nix-support/hydra-build-products
+22 -8
nixos/maintainers/scripts/openstack/openstack-image-zfs.nix
···
imports = [
../../../modules/virtualisation/openstack-config.nix
../../../modules/virtualisation/disk-size-option.nix
(lib.mkRenamedOptionModuleWith {
sinceRelease = 2411;
from = [
···
"diskSize"
];
})
] ++ (lib.optional copyChannel ../../../modules/installer/cd-dvd/channel.nix);
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 {
type = types.int;
default = (3 * 1024);
···
virtualisation.diskSize = lib.mkOverride 1490 (8 * 1024);
virtualisation.diskSizeAutoSupported = false;
system.build.openstackImage = import ../../../lib/make-single-disk-zfs-image.nix {
inherit lib config;
-
inherit (cfg) contents format name;
pkgs = import ../../../.. { inherit (pkgs) system; }; # ensure we use the regular qemu-kvm package
configFile = pkgs.writeText "configuration.nix" ''
···
postVM = ''
extension=''${rootDiskImage##*.}
-
friendlyName=$out/${cfg.name}
rootDisk="$friendlyName.root.$extension"
mv "$rootDiskImage" "$rootDisk"
···
imports = [
../../../modules/virtualisation/openstack-config.nix
../../../modules/virtualisation/disk-size-option.nix
+
../../../modules/image/file-options.nix
(lib.mkRenamedOptionModuleWith {
sinceRelease = 2411;
from = [
···
"diskSize"
];
})
+
(lib.mkRenamedOptionModuleWith {
+
sinceRelease = 2505;
+
from = [
+
"openstackImage"
+
"name"
+
];
+
to = [
+
"image"
+
"baseName"
+
];
+
})
+
] ++ (lib.optional copyChannel ../../../modules/installer/cd-dvd/channel.nix);
options.openstackImage = {
ramMB = mkOption {
type = types.int;
default = (3 * 1024);
···
virtualisation.diskSize = lib.mkOverride 1490 (8 * 1024);
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 {
inherit lib config;
+
inherit (cfg) contents format;
+
name = config.image.baseName;
pkgs = import ../../../.. { inherit (pkgs) system; }; # ensure we use the regular qemu-kvm package
configFile = pkgs.writeText "configuration.nix" ''
···
postVM = ''
extension=''${rootDiskImage##*.}
+
friendlyName=$out/${config.image.baseName}
rootDisk="$friendlyName.root.$extension"
mv "$rootDiskImage" "$rootDisk"
+7 -2
nixos/maintainers/scripts/openstack/openstack-image.nix
···
{ config, lib, pkgs, ... }:
let
copyChannel = true;
in
{
imports = [
../../../modules/virtualisation/openstack-config.nix
] ++ (lib.optional copyChannel ../../../modules/installer/cd-dvd/channel.nix);
documentation.enable = copyChannel;
system.build.openstackImage = import ../../../lib/make-disk-image.nix {
-
inherit lib config copyChannel;
additionalSpace = "1024M";
pkgs = import ../../../.. { inherit (pkgs) system; }; # ensure we use the regular qemu-kvm package
-
format = "qcow2";
configFile = pkgs.writeText "configuration.nix"
''
{
···
{ config, lib, pkgs, ... }:
let
copyChannel = true;
+
format = "qcow2";
in
{
imports = [
../../../modules/virtualisation/openstack-config.nix
+
../../../modules/image/file-options.nix
] ++ (lib.optional copyChannel ../../../modules/installer/cd-dvd/channel.nix);
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 {
+
inherit lib config copyChannel format;
+
inherit (config.image) baseName;
additionalSpace = "1024M";
pkgs = import ../../../.. { inherit (pkgs) system; }; # ensure we use the regular qemu-kvm package
configFile = pkgs.writeText "configuration.nix"
''
{
+35
nixos/modules/image/images.nix
···
inherit (lib) types;
imageModules = {
azure = [ ../virtualisation/azure-image.nix ];
digital-ocean = [ ../virtualisation/digital-ocean-image.nix ];
google-compute = [ ../virtualisation/google-compute-image.nix ];
···
lxc = [ ../virtualisation/lxc-container.nix ];
lxc-metadata = [ ../virtualisation/lxc-image-metadata.nix ];
oci = [ ../virtualisation/oci-image.nix ];
proxmox = [ ../virtualisation/proxmox-image.nix ];
kubevirt = [ ../virtualisation/kubevirt.nix ];
vagrant-virtualbox = [ ../virtualisation/vagrant-virtualbox-image.nix ];
virtualbox = [ ../virtualisation/virtualbox-image.nix ];
vmware = [ ../virtualisation/vmware-image.nix ];
};
imageConfigs = lib.mapAttrs (
name: modules:
···
inherit (lib) types;
imageModules = {
+
amazon = [ ../../maintainers/scripts/ec2/amazon-image.nix ];
azure = [ ../virtualisation/azure-image.nix ];
digital-ocean = [ ../virtualisation/digital-ocean-image.nix ];
google-compute = [ ../virtualisation/google-compute-image.nix ];
···
lxc = [ ../virtualisation/lxc-container.nix ];
lxc-metadata = [ ../virtualisation/lxc-image-metadata.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-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 ];
vagrant-virtualbox = [ ../virtualisation/vagrant-virtualbox-image.nix ];
virtualbox = [ ../virtualisation/virtualbox-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 (
name: modules:
-3
nixos/modules/installer/cd-dvd/installation-cd-base.nix
···
# Adds terminus_font for people with HiDPI displays
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
isoImage.makeEfiBootable = true;
···
# Adds terminus_font for people with HiDPI displays
console.packages = options.console.packages.default ++ [ pkgs.terminus_font ];
# EFI booting
isoImage.makeEfiBootable = true;
+31 -17
nixos/modules/installer/cd-dvd/iso-image.nix
···
in
{
-
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 {
default = false;
···
boot.loader.timeout = 10;
# Create the ISO image.
system.build.isoImage = pkgs.callPackage ../../../lib/make-iso9660-image.nix ({
-
inherit (config.isoImage) isoName compressImage volumeID contents;
bootable = config.isoImage.makeBiosBootable;
bootImage = "/isolinux/isolinux.bin";
syslinux = if config.isoImage.makeBiosBootable then pkgs.syslinux else null;
···
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 = {
isoImage.compressImage = lib.mkOption {
default = false;
···
boot.loader.timeout = 10;
# 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 ({
+
inherit (config.isoImage) compressImage volumeID contents;
+
isoName = "${config.image.baseName}.iso";
bootable = config.isoImage.makeBiosBootable;
bootImage = "/isolinux/isolinux.bin";
syslinux = if config.isoImage.makeBiosBootable then pkgs.syslinux else null;
+20 -1
nixos/modules/installer/netboot/netboot.nix
···
# This module creates netboot media containing the given NixOS
# configuration.
-
{ config, lib, pkgs, ... }:
with lib;
{
options = {
netboot.squashfsCompression = mkOption {
···
path = config.system.build.kexecScript;
}
];
boot.loader.timeout = 10;
···
# This module creates netboot media containing the given NixOS
# configuration.
+
{ config, lib, pkgs, modulesPath, ... }:
with lib;
{
+
imports = [
+
../../image/file-options.nix
+
];
+
options = {
netboot.squashfsCompression = mkOption {
···
path = config.system.build.kexecScript;
}
];
+
+
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;
+31 -17
nixos/modules/installer/sd-card/sd-image.nix
···
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" "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.")
];
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 {
type = with types; listOf package;
example = literalExpression "[ pkgs.stdenv ]";
···
sdImage.storePaths = [ config.system.build.toplevel ];
system.build.sdImage = pkgs.callPackage ({ stdenv, dosfstools, e2fsprogs,
mtools, libfaketime, util-linux, zstd }: stdenv.mkDerivation {
-
name = config.sdImage.imageName;
nativeBuildInputs = [ dosfstools e2fsprogs libfaketime mtools util-linux ]
++ lib.optional config.sdImage.compressImage zstd;
-
inherit (config.sdImage) imageName compressImage;
buildCommand = ''
mkdir -p $out/nix-support $out/sd-image
-
export img=$out/sd-image/${config.sdImage.imageName}
echo "${pkgs.stdenv.buildPlatform.system}" > $out/nix-support/system
if test -n "$compressImage"; then
···
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" "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 = {
storePaths = mkOption {
type = with types; listOf package;
example = literalExpression "[ pkgs.stdenv ]";
···
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,
mtools, libfaketime, util-linux, zstd }: stdenv.mkDerivation {
+
name = config.image.fileName;
nativeBuildInputs = [ dosfstools e2fsprogs libfaketime mtools util-linux ]
++ lib.optional config.sdImage.compressImage zstd;
+
inherit (config.sdImage) compressImage;
buildCommand = ''
mkdir -p $out/nix-support $out/sd-image
+
export img=$out/sd-image/${config.image.baseName}.img
echo "${pkgs.stdenv.buildPlatform.system}" > $out/nix-support/system
if test -n "$compressImage"; then
+61
nixos/modules/virtualisation/disk-image.nix
···
···
+
{
+
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";
+
};
+
};
+
}
+1 -1
nixos/release.nix
···
hydraJob ((import lib/eval-config.nix {
inherit system;
modules = makeModules module {
-
isoImage.isoBaseName = "nixos-${type}";
};
}).config.system.build.isoImage);
···
hydraJob ((import lib/eval-config.nix {
inherit system;
modules = makeModules module {
+
image.baseName = "nixos-${type}";
};
}).config.system.build.isoImage);
+1 -1
nixos/tests/ec2.nix
···
}
];
}).config;
-
image = "${imageCfg.system.build.amazonImage}/${imageCfg.amazonImage.name}.qcow2";
sshKeys = import ./ssh-keys.nix pkgs;
snakeOilPrivateKey = sshKeys.snakeOilPrivateKey.text;
···
}
];
}).config;
+
image = "${imageCfg.system.build.amazonImage}/${imageCfg.image.imageFile}";
sshKeys = import ./ssh-keys.nix pkgs;
snakeOilPrivateKey = sshKeys.snakeOilPrivateKey.text;
+1 -1
pkgs/desktops/gnome/installer.nix
···
config = (import ../../../../nixos/lib/eval-config.nix {
inherit system;
-
modules = [ module { isoImage.isoBaseName = isoBaseName; } ] ++ extraModules;
}).config;
in
···
config = (import ../../../../nixos/lib/eval-config.nix {
inherit system;
+
modules = [ module { image.baseName = isoBaseName; } ] ++ extraModules;
}).config;
in