about summary refs log tree commit diff
path: root/corp/ops/modules/yandex-cloud.nix
blob: cca81bc0ca5ef03248e9ff1a8b629923605406e6 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Profile for virtual machines on Yandex Cloud, intended for disk
# images.
#
# https://cloud.yandex.com/en/docs/compute/operations/image-create/custom-image
#
# TODO(tazjin): Upstream to nixpkgs once it works well.
{ config, lib, pkgs, modulesPath, ... }:

let
  cfg = config.virtualisation.yandexCloud;

  # Kernel modules required for interacting with the hypervisor. These
  # must be available during stage 1 boot and during normal operation,
  # as disks and network do not work without them.
  modules = [
    "virtio-net"
    "virtio-blk"
    "virtio-pci"
    "virtiofs"
  ];
in
{
  imports = [
    "${modulesPath}/profiles/headless.nix"
  ];

  options = {
    virtualisation.yandexCloud.rootPartitionUuid = with lib; mkOption {
      type = types.str;
      default = "C55A5EE2-E5FA-485C-B3AE-CC928429AB6B";

      description = ''
        UUID to use for the root partition of the disk image. Yandex
        Cloud requires that root partitions are mounted by UUID.

        Most users do not need to set this to a non-default value.
      '';
    };
  };

  config = {
    fileSystems."/" = {
      device = "/dev/disk/by-uuid/${lib.toLower cfg.rootPartitionUuid}";
      fsType = "ext4";
      autoResize = true;
    };

    boot = {
      loader.grub.device = "/dev/vda";

      initrd.kernelModules = modules;
      kernelModules = modules;
      kernelParams = [
        # Enable support for the serial console
        "console=ttyS0"
      ];

      growPartition = true;
    };

    environment.etc.securetty = {
      text = "ttyS0";
      mode = "0644";
    };

    systemd.services."serial-getty@ttyS0".enable = true;

    services.openssh.enable = true;
    services.cloud-init.enable = true;

    system.build.yandexCloudImage = import (pkgs.path + "/nixos/lib/make-disk-image.nix") {
      inherit lib config pkgs;
      additionalSpace = "128M";
      format = "qcow2";
      partitionTableType = "legacy+gpt";
      rootGPUID = cfg.rootPartitionUuid;
    };
  };
}