2023-09-10 12:48:41 +00:00
|
|
|
{ config, lib, pkgs, extendModules, ... }@args:
|
2022-10-23 10:29:30 +00:00
|
|
|
let
|
2023-05-16 11:40:03 +00:00
|
|
|
diskoLib = import ./lib {
|
2023-01-24 14:57:17 +00:00
|
|
|
inherit lib;
|
2023-02-07 15:37:12 +00:00
|
|
|
rootMountPoint = config.disko.rootMountPoint;
|
2023-07-20 19:32:53 +00:00
|
|
|
makeTest = import (pkgs.path + "/nixos/tests/make-test-python.nix");
|
|
|
|
eval-config = import (pkgs.path + "/nixos/lib/eval-config.nix");
|
2023-01-24 14:57:17 +00:00
|
|
|
};
|
2022-10-23 10:29:30 +00:00
|
|
|
cfg = config.disko;
|
2023-02-06 14:24:34 +00:00
|
|
|
in
|
|
|
|
{
|
2022-10-23 10:29:30 +00:00
|
|
|
options.disko = {
|
2024-07-08 19:12:36 +00:00
|
|
|
imageBuilderQemu = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.str;
|
|
|
|
description = ''
|
|
|
|
the qemu emulator string used when building disk images via make-disk-image.nix.
|
|
|
|
Useful when using binfmt on your build host, and wanting to build disk
|
|
|
|
images for a foreign architecture
|
|
|
|
'';
|
|
|
|
default = null;
|
|
|
|
example = lib.literalExpression "''${pkgs.qemu_kvm}/bin/qemu-system-aarch64";
|
|
|
|
};
|
2024-07-08 19:11:00 +00:00
|
|
|
imageBuilderPkgs = lib.mkOption {
|
|
|
|
type = lib.types.attrs;
|
|
|
|
description = ''
|
|
|
|
the pkgs instance used when building disk images via make-disk-image.nix.
|
|
|
|
Useful when the config's kernel won't boot in the image-builder.
|
|
|
|
'';
|
|
|
|
default = pkgs;
|
2024-08-20 12:06:57 +00:00
|
|
|
defaultText = lib.literalExpression "pkgs";
|
2024-07-08 19:11:00 +00:00
|
|
|
example = lib.literalExpression "pkgs";
|
|
|
|
};
|
2024-07-03 18:53:13 +00:00
|
|
|
imageBuilderKernelPackages = lib.mkOption {
|
|
|
|
type = lib.types.attrs;
|
|
|
|
description = ''
|
|
|
|
the kernel used when building disk images via make-disk-image.nix.
|
|
|
|
Useful when the config's kernel won't boot in the image-builder.
|
|
|
|
'';
|
|
|
|
default = config.boot.kernelPackages;
|
2024-08-18 15:36:27 +00:00
|
|
|
defaultText = lib.literalExpression "config.boot.kernelPackages";
|
2024-07-03 18:53:13 +00:00
|
|
|
example = lib.literalExpression "pkgs.linuxPackages_testing";
|
|
|
|
};
|
2023-12-14 12:01:52 +00:00
|
|
|
extraRootModules = lib.mkOption {
|
2023-12-24 16:12:23 +00:00
|
|
|
type = lib.types.listOf lib.types.str;
|
2023-12-14 12:01:52 +00:00
|
|
|
description = ''
|
2024-06-24 13:25:25 +00:00
|
|
|
extra kernel modules to pass to the vmTools.runCommand invocation in the make-disk-image.nix builder
|
2023-12-14 12:01:52 +00:00
|
|
|
'';
|
2023-12-24 16:12:23 +00:00
|
|
|
default = [ ];
|
2024-06-24 13:25:25 +00:00
|
|
|
example = [ "bcachefs" ];
|
2023-12-14 12:01:52 +00:00
|
|
|
};
|
2024-05-19 12:11:09 +00:00
|
|
|
extraPostVM = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
description = ''
|
|
|
|
extra shell code to execute once the disk image(s) have been succesfully created and moved to $out
|
|
|
|
'';
|
|
|
|
default = "";
|
2024-05-22 11:26:40 +00:00
|
|
|
example = lib.literalExpression ''
|
2024-05-19 12:11:09 +00:00
|
|
|
''${pkgs.zstd}/bin/zstd --compress $out/*raw
|
|
|
|
rm $out/*raw
|
|
|
|
'';
|
|
|
|
};
|
2023-12-12 22:47:37 +00:00
|
|
|
memSize = lib.mkOption {
|
|
|
|
type = lib.types.int;
|
|
|
|
description = ''
|
|
|
|
size of the memory passed to runInLinuxVM, in megabytes
|
|
|
|
'';
|
|
|
|
default = 1024;
|
|
|
|
};
|
2022-10-23 10:29:30 +00:00
|
|
|
devices = lib.mkOption {
|
2023-07-13 13:08:20 +00:00
|
|
|
type = diskoLib.toplevel;
|
2023-02-06 14:24:34 +00:00
|
|
|
default = { };
|
2023-01-03 18:52:57 +00:00
|
|
|
description = "The devices to set up";
|
2022-10-23 10:29:30 +00:00
|
|
|
};
|
2023-12-14 13:51:55 +00:00
|
|
|
extraDependencies = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.package;
|
|
|
|
description = ''
|
|
|
|
list of extra packages to make available in the make-disk-image.nix VM builder, an example might be f2fs-tools
|
|
|
|
'';
|
2023-12-24 16:12:23 +00:00
|
|
|
default = [ ];
|
2023-12-14 13:51:55 +00:00
|
|
|
};
|
2023-01-24 14:57:17 +00:00
|
|
|
rootMountPoint = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "/mnt";
|
|
|
|
description = "Where the device tree should be mounted by the mountScript";
|
|
|
|
};
|
2022-10-23 10:29:30 +00:00
|
|
|
enableConfig = lib.mkOption {
|
|
|
|
description = ''
|
|
|
|
configure nixos with the specified devices
|
|
|
|
should be true if the system is booted with those devices
|
|
|
|
should be false on an installer image etc.
|
|
|
|
'';
|
|
|
|
type = lib.types.bool;
|
|
|
|
default = true;
|
|
|
|
};
|
2023-01-30 20:36:51 +00:00
|
|
|
checkScripts = lib.mkOption {
|
|
|
|
description = ''
|
|
|
|
Whether to run shellcheck on script outputs
|
|
|
|
'';
|
|
|
|
type = lib.types.bool;
|
|
|
|
default = false;
|
|
|
|
};
|
2023-07-20 16:32:47 +00:00
|
|
|
tests = {
|
|
|
|
efi = lib.mkOption {
|
|
|
|
description = ''
|
|
|
|
Whether efi is enabled for the `system.build.installTest`.
|
|
|
|
We try to automatically detect efi based on the configured bootloader.
|
|
|
|
'';
|
|
|
|
type = lib.types.bool;
|
2023-10-13 17:52:29 +00:00
|
|
|
defaultText = "config.boot.loader.systemd-boot.enable || config.boot.loader.grub.efiSupport";
|
2023-07-20 16:32:47 +00:00
|
|
|
default = config.boot.loader.systemd-boot.enable || config.boot.loader.grub.efiSupport;
|
|
|
|
};
|
2023-09-02 09:01:41 +00:00
|
|
|
extraChecks = lib.mkOption {
|
|
|
|
description = ''
|
|
|
|
extra checks to run in the `system.build.installTest`.
|
|
|
|
'';
|
|
|
|
type = lib.types.lines;
|
|
|
|
default = "";
|
|
|
|
example = ''
|
|
|
|
machine.succeed("test -e /var/secrets/my.secret")
|
|
|
|
'';
|
|
|
|
};
|
2023-08-07 17:18:05 +00:00
|
|
|
extraConfig = lib.mkOption {
|
|
|
|
description = ''
|
|
|
|
Extra NixOS config for your test. Can be used to specify a different luks key for tests.
|
|
|
|
A dummy key is in /tmp/secret.key
|
|
|
|
'';
|
2023-09-15 05:56:40 +00:00
|
|
|
default = { };
|
2023-08-07 17:18:05 +00:00
|
|
|
};
|
2023-07-20 16:32:47 +00:00
|
|
|
};
|
2022-10-23 10:29:30 +00:00
|
|
|
};
|
2023-02-06 14:24:34 +00:00
|
|
|
config = lib.mkIf (cfg.devices.disk != { }) {
|
2023-07-13 13:08:20 +00:00
|
|
|
system.build = (cfg.devices._scripts { inherit pkgs; checked = cfg.checkScripts; }) // {
|
2022-11-23 12:29:51 +00:00
|
|
|
|
2023-07-30 17:12:24 +00:00
|
|
|
# we keep these old outputs for compatibility
|
2023-12-24 16:12:23 +00:00
|
|
|
disko = builtins.trace "the .disko output is deprecated, please use .diskoScript instead" (cfg.devices._scripts { inherit pkgs; }).diskoScript;
|
|
|
|
diskoNoDeps = builtins.trace "the .diskoNoDeps output is deprecated, please use .diskoScriptNoDeps instead" (cfg.devices._scripts { inherit pkgs; }).diskoScriptNoDeps;
|
2023-07-20 16:32:47 +00:00
|
|
|
|
2023-09-14 15:06:31 +00:00
|
|
|
diskoImages = diskoLib.makeDiskImages {
|
2023-09-10 12:48:41 +00:00
|
|
|
nixosConfig = args;
|
|
|
|
};
|
2023-09-14 15:06:31 +00:00
|
|
|
diskoImagesScript = diskoLib.makeDiskImagesScript {
|
2023-09-10 12:48:41 +00:00
|
|
|
nixosConfig = args;
|
|
|
|
};
|
|
|
|
|
2023-07-20 16:32:47 +00:00
|
|
|
installTest = diskoLib.testLib.makeDiskoTest {
|
|
|
|
inherit extendModules pkgs;
|
|
|
|
name = "${config.networking.hostName}-disko";
|
2023-08-11 06:11:01 +00:00
|
|
|
disko-config = builtins.removeAttrs config [ "_module" ];
|
2023-07-20 16:32:47 +00:00
|
|
|
testMode = "direct";
|
|
|
|
efi = cfg.tests.efi;
|
2023-08-07 17:18:05 +00:00
|
|
|
extraSystemConfig = cfg.tests.extraConfig;
|
2023-09-02 09:01:41 +00:00
|
|
|
extraTestScript = cfg.tests.extraChecks;
|
2023-07-20 16:32:47 +00:00
|
|
|
};
|
2023-07-13 13:08:20 +00:00
|
|
|
};
|
2023-06-23 02:57:57 +00:00
|
|
|
|
2022-11-27 15:50:43 +00:00
|
|
|
|
2023-07-13 13:08:20 +00:00
|
|
|
# we need to specify the keys here, so we don't get an infinite recursion error
|
2022-10-23 10:29:30 +00:00
|
|
|
# Remember to add config keys here if they are added to types
|
2023-08-11 06:11:01 +00:00
|
|
|
fileSystems = lib.mkIf cfg.enableConfig cfg.devices._config.fileSystems or { };
|
|
|
|
boot = lib.mkIf cfg.enableConfig cfg.devices._config.boot or { };
|
|
|
|
swapDevices = lib.mkIf cfg.enableConfig cfg.devices._config.swapDevices or [ ];
|
2022-10-23 10:29:30 +00:00
|
|
|
};
|
|
|
|
}
|