nixfiles/nixos/modules/build.nix

120 lines
3.6 KiB
Nix
Raw Normal View History

{ lib, pkgs, extendModules, modulesPath, 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
{
# Doesn't work right now... (missing /dev/root)
boot.initrd.systemd.enable = false;
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
({ pkgs, config, ... }: {
system.build.netbootArchive = pkgs.runCommand "netboot-${config.system.name}-archive.tar" { } ''
${pkgs.gnutar}/bin/tar -rvC "${config.system.build.kernel}" \
-f "$out" "${config.system.boot.loader.kernelFile}"
${pkgs.gnutar}/bin/tar -rvC "${config.system.build.netbootRamdisk}" \
-f "$out" initrd
${pkgs.gnutar}/bin/tar -rvC "${config.system.build.netbootIpxeScript}" \
-f "$out" netboot.ipxe
'';
})
2022-06-16 19:40:47 +01:00
];
};
mkAsOpt = ext: desc: with lib.types; mkOption {
type = unspecified;
default = ext;
2022-06-16 19:40:47 +01:00
visible = "shallow";
description = "Configuration as ${desc}.";
};
2022-02-17 15:47:24 +00:00
in
{
options = {
2022-02-17 15:47:24 +00:00
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;
cores = dummyOption;
memorySize = dummyOption;
qemu.options = dummyOption;
2022-02-17 15:47:24 +00:00
};
2022-06-12 20:47:28 +01:00
isoImage = {
isoBaseName = dummyOption;
volumeID = dummyOption;
2022-06-12 20:47:28 +01:00
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.config.system.build.vm { meta.mainProgram = "run-${config.system.name}-vm"; };
iso = config.my.asISO.config.system.build.isoImage;
container = config.my.asContainer.config.system.build.toplevel;
kexecTree = config.my.asKexecTree.config.system.build.kexecTree;
netbootArchive = config.my.asKexecTree.config.system.build.netbootArchive;
2022-02-17 15:47:24 +00:00
};
};
};
meta.buildDocsInSandbox = false;
}