2022-06-16 19:40:47 +01:00
|
|
|
{ lib, pkgs, extendModules, modulesPath, baseModules, options, config, ... }:
|
2022-02-17 15:47:24 +00:00
|
|
|
let
|
2022-06-16 19:40:47 +01:00
|
|
|
inherit (lib) recursiveUpdate mkOption mkDefault mkIf mkMerge flatten optional;
|
2022-02-17 15:47:24 +00:00
|
|
|
inherit (lib.my) mkBoolOpt' dummyOption;
|
|
|
|
|
|
|
|
cfg = config.my.build;
|
|
|
|
|
2022-06-16 19:40:47 +01:00
|
|
|
allHardware = (optional config.my.build.allHardware { imports = [ "${modulesPath}/profiles/all-hardware.nix" ]; });
|
|
|
|
|
2022-02-17 15:47:24 +00:00
|
|
|
asDevVM = extendModules {
|
|
|
|
modules = [
|
|
|
|
"${modulesPath}/virtualisation/qemu-vm.nix"
|
|
|
|
{ my.build.isDevVM = true; }
|
|
|
|
];
|
|
|
|
};
|
|
|
|
asISO = extendModules {
|
2022-06-16 19:40:47 +01:00
|
|
|
modules = flatten [
|
2022-02-17 15:47:24 +00:00
|
|
|
"${modulesPath}/installer/cd-dvd/iso-image.nix"
|
2022-06-16 19:40:47 +01:00
|
|
|
allHardware
|
2022-02-17 15:47:24 +00:00
|
|
|
{
|
|
|
|
isoImage = {
|
|
|
|
makeEfiBootable = true;
|
|
|
|
makeUsbBootable = true;
|
|
|
|
# Not necessarily an installer
|
|
|
|
appendToMenuLabel = mkDefault "";
|
|
|
|
|
|
|
|
squashfsCompression = "zstd -Xcompression-level 8";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
2022-03-26 14:20:30 +00:00
|
|
|
asContainer = extendModules {
|
|
|
|
modules = [
|
|
|
|
{
|
|
|
|
boot.isContainer = true;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
2022-06-16 19:40:47 +01:00
|
|
|
asKexecTree = extendModules {
|
|
|
|
modules = flatten [
|
|
|
|
"${modulesPath}/installer/netboot/netboot.nix"
|
|
|
|
allHardware
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
mkAsOpt = ext: desc: mkOption {
|
|
|
|
inherit (ext) type;
|
|
|
|
default = { };
|
|
|
|
visible = "shallow";
|
|
|
|
description = "Configuration as ${desc}.";
|
|
|
|
};
|
2022-02-17 15:47:24 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = with lib.types; {
|
|
|
|
my = {
|
|
|
|
build = {
|
|
|
|
isDevVM = mkBoolOpt' false "Whether the system is a development VM.";
|
|
|
|
allHardware = mkBoolOpt' false
|
|
|
|
("Whether to enable a lot of firmware and kernel modules for a wide range of hardware." +
|
|
|
|
"Only applies to some build targets.");
|
|
|
|
};
|
|
|
|
|
2022-06-16 19:40:47 +01:00
|
|
|
asDevVM = mkAsOpt asDevVM "a development VM";
|
|
|
|
asISO = mkAsOpt asISO "a bootable .iso image";
|
|
|
|
asContainer = mkAsOpt asContainer "a container";
|
|
|
|
asKexecTree = mkAsOpt asKexecTree "a kexec-able kernel and initrd";
|
2022-02-17 15:47:24 +00:00
|
|
|
|
|
|
|
buildAs = options.system.build;
|
|
|
|
};
|
|
|
|
|
|
|
|
# Forward declare options that won't exist until the VM module is actually imported
|
|
|
|
virtualisation = {
|
|
|
|
diskImage = dummyOption;
|
2022-02-17 19:14:10 +00:00
|
|
|
forwardPorts = dummyOption;
|
2022-02-22 01:30:27 +00:00
|
|
|
sharedDirectories = dummyOption;
|
2022-05-02 20:40:11 +01:00
|
|
|
cores = dummyOption;
|
|
|
|
memorySize = dummyOption;
|
2022-05-16 00:05:02 +01:00
|
|
|
qemu.options = dummyOption;
|
2022-02-17 15:47:24 +00:00
|
|
|
};
|
2022-06-12 20:47:28 +01:00
|
|
|
isoImage = {
|
|
|
|
isoBaseName = dummyOption;
|
|
|
|
edition = dummyOption;
|
|
|
|
appendToMenuLabel = dummyOption;
|
|
|
|
};
|
2022-02-17 15:47:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
virtualisation = {
|
|
|
|
diskImage = mkDefault "./.vms/${config.system.name}.qcow2";
|
|
|
|
};
|
|
|
|
|
|
|
|
my = {
|
|
|
|
buildAs = {
|
|
|
|
# The meta.mainProgram should probably be set upstream but oh well...
|
|
|
|
devVM = recursiveUpdate config.my.asDevVM.system.build.vm { meta.mainProgram = "run-${config.system.name}-vm"; };
|
|
|
|
iso = config.my.asISO.system.build.isoImage;
|
2022-03-26 14:20:30 +00:00
|
|
|
container = config.my.asContainer.system.build.toplevel;
|
2022-06-16 19:40:47 +01:00
|
|
|
kexecTree = config.my.asKexecTree.system.build.kexecTree;
|
2022-02-17 15:47:24 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
meta.buildDocsInSandbox = false;
|
|
|
|
}
|