summary refs log tree commit diff
path: root/nixos/modules/virtualisation/build-vm.nix
blob: 4a4694950f98850a5e5e5cfb05094248b92f657e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
{ config, extendModules, lib, ... }:
let

  inherit (lib)
    mkOption
    ;

  vmVariant = extendModules {
    modules = [ ./qemu-vm.nix ];
  };

  vmVariantWithBootLoader = vmVariant.extendModules {
    modules = [
      ({ config, ... }: {
        _file = "nixos/default.nix##vmWithBootLoader";
        virtualisation.useBootLoader = true;
        virtualisation.useEFIBoot =
          config.boot.loader.systemd-boot.enable ||
          config.boot.loader.efi.canTouchEfiVariables;
      })
    ];
  };
in
{
  options = {

    virtualisation.vmVariant = mkOption {
      description = ''
        Machine configuration to be added for the vm script produced by <literal>nixos-rebuild build-vm</literal>.
      '';
      inherit (vmVariant) type;
      default = {};
      visible = "shallow";
    };

    virtualisation.vmVariantWithBootLoader = mkOption {
      description = ''
        Machine configuration to be added for the vm script produced by <literal>nixos-rebuild build-vm-with-bootloader</literal>.
      '';
      inherit (vmVariantWithBootLoader) type;
      default = {};
      visible = "shallow";
    };

  };

  config = {

    system.build = {
      vm = lib.mkDefault config.virtualisation.vmVariant.system.build.vm;
      vmWithBootLoader = lib.mkDefault config.virtualisation.vmVariantWithBootLoader.system.build.vm;
    };

  };

  # uses extendModules
  meta.buildDocsInSandbox = false;
}