Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
36 changes: 22 additions & 14 deletions nixos/maintainers/scripts/ec2/amazon-image.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ in
imports = [
../../../modules/virtualisation/amazon-image.nix
../../../modules/virtualisation/disk-size-option.nix
../../../modules/image/file-options.nix
(lib.mkRenamedOptionModuleWith {
sinceRelease = 2411;
from = [
Expand All @@ -31,6 +32,17 @@ in
"diskSize"
];
})
(lib.mkRenamedOptionModuleWith {
sinceRelease = 2505;
from = [
"amazonImage"
"name"
];
to = [
"image"
"baseName"
];
})
];

# Amazon recommends setting this to the highest possible value for a good EBS
Expand All @@ -44,12 +56,6 @@ in
[ "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";
Expand Down Expand Up @@ -80,6 +86,10 @@ in
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" ''
Expand All @@ -102,7 +112,8 @@ in
configFile
pkgs
;
inherit (cfg) contents format name;
inherit (cfg) contents format;
name = config.image.baseName;

includeChannel = true;

Expand All @@ -118,7 +129,7 @@ in

postVM = ''
extension=''${rootDiskImage##*.}
friendlyName=$out/${cfg.name}
friendlyName=$out/${config.image.baseName}
rootDisk="$friendlyName.root.$extension"
bootDisk="$friendlyName.boot.$extension"
mv "$rootDiskImage" "$rootDisk"
Expand Down Expand Up @@ -156,19 +167,16 @@ in
pkgs
;

inherit (cfg) contents format name;
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 = ''
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

Expand Down
30 changes: 22 additions & 8 deletions nixos/maintainers/scripts/openstack/openstack-image-zfs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ in
imports = [
../../../modules/virtualisation/openstack-config.nix
../../../modules/virtualisation/disk-size-option.nix
../../../modules/image/file-options.nix
(lib.mkRenamedOptionModuleWith {
sinceRelease = 2411;
from = [
Expand All @@ -27,15 +28,21 @@ in
"diskSize"
];
})
(lib.mkRenamedOptionModuleWith {
sinceRelease = 2505;
from = [
"openstackImage"
"name"
];
to = [
"image"
"baseName"
];
})

] ++ (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);
Expand Down Expand Up @@ -72,9 +79,16 @@ in
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;
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" ''
Expand All @@ -98,7 +112,7 @@ in

postVM = ''
extension=''${rootDiskImage##*.}
friendlyName=$out/${cfg.name}
friendlyName=$out/${config.image.baseName}
rootDisk="$friendlyName.root.$extension"
mv "$rootDiskImage" "$rootDisk"

Expand Down
9 changes: 7 additions & 2 deletions nixos/maintainers/scripts/openstack/openstack-image.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@
{ 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;
inherit lib config copyChannel format;
inherit (config.image) baseName;
additionalSpace = "1024M";
pkgs = import ../../../.. { inherit (pkgs) system; }; # ensure we use the regular qemu-kvm package
format = "qcow2";
configFile = pkgs.writeText "configuration.nix"
''
{
Expand Down
35 changes: 35 additions & 0 deletions nixos/modules/image/images.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ let
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 ];
Expand All @@ -17,11 +18,45 @@ let
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:
Expand Down
3 changes: 0 additions & 3 deletions nixos/modules/installer/cd-dvd/installation-cd-base.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
# 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;

Expand Down
48 changes: 31 additions & 17 deletions nixos/modules/installer/cd-dvd/iso-image.nix
Original file line number Diff line number Diff line change
Expand Up @@ -476,23 +476,33 @@ let
in

{
options = {

isoImage.isoName = lib.mkOption {
default = "${config.isoImage.isoBaseName}.iso";
type = lib.types.str;
description = ''
Name of the generated ISO image file.
'';
};
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
];

isoImage.isoBaseName = lib.mkOption {
default = config.system.nixos.distroId;
type = lib.types.str;
description = ''
Prefix of the name of the generated ISO image file.
'';
};
options = {

isoImage.compressImage = lib.mkOption {
default = false;
Expand Down Expand Up @@ -858,8 +868,12 @@ in
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) isoName compressImage volumeID contents;
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;
Expand Down
21 changes: 20 additions & 1 deletion nixos/modules/installer/netboot/netboot.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# This module creates netboot media containing the given NixOS
# configuration.

{ config, lib, pkgs, ... }:
{ config, lib, pkgs, modulesPath, ... }:

with lib;

{
imports = [
../../image/file-options.nix
];

options = {

netboot.squashfsCompression = mkOption {
Expand Down Expand Up @@ -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.postBootCommands =
Expand Down
Loading