image/images: Adapt remaining images to system.build.image & normalized filenames, (#359345)
This commit is contained in:
@@ -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 = [
|
||||
@@ -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
|
||||
@@ -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";
|
||||
@@ -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" ''
|
||||
@@ -102,7 +112,8 @@ in
|
||||
configFile
|
||||
pkgs
|
||||
;
|
||||
inherit (cfg) contents format name;
|
||||
inherit (cfg) contents format;
|
||||
name = config.image.baseName;
|
||||
|
||||
includeChannel = true;
|
||||
|
||||
@@ -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"
|
||||
@@ -156,7 +167,9 @@ 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";
|
||||
@@ -164,11 +177,6 @@ in
|
||||
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
|
||||
|
||||
|
||||
@@ -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 = [
|
||||
@@ -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);
|
||||
@@ -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" ''
|
||||
@@ -98,7 +112,7 @@ in
|
||||
|
||||
postVM = ''
|
||||
extension=''${rootDiskImage##*.}
|
||||
friendlyName=$out/${cfg.name}
|
||||
friendlyName=$out/${config.image.baseName}
|
||||
rootDisk="$friendlyName.root.$extension"
|
||||
mv "$rootDiskImage" "$rootDisk"
|
||||
|
||||
|
||||
@@ -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"
|
||||
''
|
||||
{
|
||||
|
||||
@@ -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 ];
|
||||
@@ -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:
|
||||
|
||||
@@ -15,9 +15,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;
|
||||
|
||||
|
||||
@@ -476,24 +476,34 @@ let
|
||||
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.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;
|
||||
type = lib.types.bool;
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
@@ -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 = ''
|
||||
|
||||
@@ -29,23 +29,33 @@ in
|
||||
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 = {
|
||||
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 ]";
|
||||
@@ -180,18 +190,22 @@ in
|
||||
|
||||
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.sdImage.imageName;
|
||||
name = config.image.fileName;
|
||||
|
||||
nativeBuildInputs = [ dosfstools e2fsprogs libfaketime mtools util-linux ]
|
||||
++ lib.optional config.sdImage.compressImage zstd;
|
||||
|
||||
inherit (config.sdImage) imageName compressImage;
|
||||
inherit (config.sdImage) compressImage;
|
||||
|
||||
buildCommand = ''
|
||||
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
|
||||
if test -n "$compressImage"; then
|
||||
|
||||
61
nixos/modules/virtualisation/disk-image.nix
Normal file
61
nixos/modules/virtualisation/disk-image.nix
Normal 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";
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -62,7 +62,7 @@ let
|
||||
hydraJob ((import lib/eval-config.nix {
|
||||
inherit system;
|
||||
modules = makeModules module {
|
||||
isoImage.isoBaseName = "nixos-${type}";
|
||||
image.baseName = "nixos-${type}";
|
||||
};
|
||||
}).config.system.build.isoImage);
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ let
|
||||
}
|
||||
];
|
||||
}).config;
|
||||
image = "${imageCfg.system.build.amazonImage}/${imageCfg.amazonImage.name}.qcow2";
|
||||
image = "${imageCfg.system.build.amazonImage}/${imageCfg.image.imageFile}";
|
||||
|
||||
sshKeys = import ./ssh-keys.nix pkgs;
|
||||
snakeOilPrivateKey = sshKeys.snakeOilPrivateKey.text;
|
||||
|
||||
@@ -7,7 +7,7 @@ let
|
||||
|
||||
config = (import ../../../../nixos/lib/eval-config.nix {
|
||||
inherit system;
|
||||
modules = [ module { isoImage.isoBaseName = isoBaseName; } ] ++ extraModules;
|
||||
modules = [ module { image.baseName = isoBaseName; } ] ++ extraModules;
|
||||
}).config;
|
||||
|
||||
in
|
||||
|
||||
Reference in New Issue
Block a user