2015-09-27 21:01:43 +02:00
|
|
|
# Configuration for Amazon EC2 instances. (Note that this file is a
|
|
|
|
# misnomer - it should be "amazon-config.nix" or so, not
|
|
|
|
# "amazon-image.nix", since it's used not only to build images but
|
|
|
|
# also to reconfigure instances. However, we can't rename it because
|
|
|
|
# existing "configuration.nix" files on EC2 instances refer to it.)
|
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2010-01-20 18:10:02 +00:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2014-05-21 10:55:34 +02:00
|
|
|
|
2019-02-06 12:16:22 +01:00
|
|
|
let
|
|
|
|
cfg = config.ec2;
|
|
|
|
in
|
2014-05-21 10:55:34 +02:00
|
|
|
|
2015-09-27 21:01:43 +02:00
|
|
|
{
|
2021-08-20 12:36:54 -04:00
|
|
|
imports = [
|
|
|
|
../profiles/headless.nix
|
|
|
|
# Note: While we do use the headless profile, we also explicitly
|
|
|
|
# turn on the serial console on ttyS0 below. This is because
|
|
|
|
# AWS does support accessing the serial console:
|
|
|
|
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configure-access-to-serial-console.html
|
|
|
|
./ec2-data.nix
|
|
|
|
./amazon-init.nix
|
|
|
|
];
|
2014-05-21 10:55:34 +02:00
|
|
|
|
2015-09-27 21:01:43 +02:00
|
|
|
config = {
|
2014-05-21 10:55:34 +02:00
|
|
|
|
2017-04-04 13:07:15 +02:00
|
|
|
assertions = [
|
2022-05-08 16:48:49 -07:00
|
|
|
{ assertion = versionOlder config.boot.kernelPackages.kernel.version "5.17";
|
|
|
|
message = "ENA driver fails to build with kernel >= 5.17";
|
2022-02-10 17:56:58 +10:00
|
|
|
}
|
2017-04-04 13:07:15 +02:00
|
|
|
];
|
|
|
|
|
2022-11-14 16:40:21 +01:00
|
|
|
boot.growPartition = true;
|
2016-02-17 13:02:59 +01:00
|
|
|
|
2021-08-25 09:38:46 -04:00
|
|
|
fileSystems."/" = mkIf (!cfg.zfs.enable) {
|
2015-09-27 21:01:43 +02:00
|
|
|
device = "/dev/disk/by-label/nixos";
|
2019-03-14 10:30:20 +01:00
|
|
|
fsType = "ext4";
|
2015-09-27 21:01:43 +02:00
|
|
|
autoResize = true;
|
|
|
|
};
|
2014-05-21 10:55:34 +02:00
|
|
|
|
2021-08-25 09:38:46 -04:00
|
|
|
fileSystems."/boot" = mkIf (cfg.efi || cfg.zfs.enable) {
|
|
|
|
# The ZFS image uses a partition labeled ESP whether or not we're
|
|
|
|
# booting with EFI.
|
2019-05-25 18:53:15 +09:00
|
|
|
device = "/dev/disk/by-label/ESP";
|
|
|
|
fsType = "vfat";
|
|
|
|
};
|
|
|
|
|
2021-08-25 09:38:46 -04:00
|
|
|
services.zfs.expandOnBoot = mkIf cfg.zfs.enable "all";
|
|
|
|
|
|
|
|
boot.zfs.devNodes = mkIf cfg.zfs.enable "/dev/";
|
|
|
|
|
2019-08-15 07:58:22 +08:00
|
|
|
boot.extraModulePackages = [
|
|
|
|
config.boot.kernelPackages.ena
|
|
|
|
];
|
2022-11-14 18:19:29 +01:00
|
|
|
boot.initrd.kernelModules = [ "xen-blkfront" ];
|
|
|
|
boot.initrd.availableKernelModules = [ "nvme" ];
|
2022-11-14 16:40:21 +01:00
|
|
|
boot.kernelParams = [ "console=ttyS0,115200n8" "random.trust_cpu=on" ];
|
2014-05-21 10:55:34 +02:00
|
|
|
|
2015-02-17 23:18:11 +01:00
|
|
|
# Prevent the nouveau kernel module from being loaded, as it
|
|
|
|
# interferes with the nvidia/nvidia-uvm modules needed for CUDA.
|
2015-09-28 21:57:54 +02:00
|
|
|
# Also blacklist xen_fbfront to prevent a 30 second delay during
|
|
|
|
# boot.
|
|
|
|
boot.blacklistedKernelModules = [ "nouveau" "xen_fbfront" ];
|
2015-02-17 23:18:11 +01:00
|
|
|
|
2022-11-14 16:40:21 +01:00
|
|
|
boot.loader.grub.device = if cfg.efi then "nodev" else "/dev/xvda";
|
2019-05-25 18:53:15 +09:00
|
|
|
boot.loader.grub.efiSupport = cfg.efi;
|
|
|
|
boot.loader.grub.efiInstallAsRemovable = cfg.efi;
|
2021-08-20 11:20:30 -04:00
|
|
|
boot.loader.timeout = 1;
|
2021-08-20 11:22:07 -04:00
|
|
|
boot.loader.grub.extraConfig = ''
|
|
|
|
serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1
|
|
|
|
terminal_output console serial
|
|
|
|
terminal_input console serial
|
|
|
|
'';
|
2014-05-21 10:55:34 +02:00
|
|
|
|
2022-11-14 18:19:29 +01:00
|
|
|
systemd.services.fetch-ec2-metadata = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2022-11-17 19:44:52 +01:00
|
|
|
after = ["network-online.target"];
|
|
|
|
path = [ pkgs.curl ];
|
|
|
|
script = builtins.readFile ./ec2-metadata-fetcher.sh;
|
2022-11-14 18:19:29 +01:00
|
|
|
serviceConfig.Type = "oneshot";
|
2022-11-17 19:44:52 +01:00
|
|
|
serviceConfig.StandardOutput = "journal+console";
|
2022-11-14 18:19:29 +01:00
|
|
|
};
|
2014-05-21 10:55:34 +02:00
|
|
|
|
|
|
|
# Allow root logins only using the SSH key that the user specified
|
|
|
|
# at instance creation time.
|
|
|
|
services.openssh.enable = true;
|
2023-01-15 16:32:46 +01:00
|
|
|
services.openssh.settings.PermitRootLogin = "prohibit-password";
|
2014-05-21 10:55:34 +02:00
|
|
|
|
2021-08-20 12:36:54 -04:00
|
|
|
# Enable the serial console on ttyS0
|
|
|
|
systemd.services."serial-getty@ttyS0".enable = true;
|
|
|
|
|
2019-08-23 21:12:33 +09:00
|
|
|
# Creates symlinks for block device names.
|
2022-02-01 14:59:59 -07:00
|
|
|
services.udev.packages = [ pkgs.amazon-ec2-utils ];
|
2019-08-23 21:12:33 +09:00
|
|
|
|
2014-05-21 10:55:34 +02:00
|
|
|
# Force getting the hostname from EC2.
|
|
|
|
networking.hostName = mkDefault "";
|
|
|
|
|
|
|
|
# Always include cryptsetup so that Charon can use it.
|
|
|
|
environment.systemPackages = [ pkgs.cryptsetup ];
|
|
|
|
|
2017-11-29 22:48:00 -05:00
|
|
|
# EC2 has its own NTP server provided by the hypervisor
|
|
|
|
networking.timeServers = [ "169.254.169.123" ];
|
2018-10-15 21:47:51 +02:00
|
|
|
|
|
|
|
# udisks has become too bloated to have in a headless system
|
2019-09-04 00:49:40 +02:00
|
|
|
# (e.g. it depends on GTK).
|
2018-10-15 21:47:51 +02:00
|
|
|
services.udisks2.enable = false;
|
2014-05-21 10:55:34 +02:00
|
|
|
};
|
2010-01-20 18:10:02 +00:00
|
|
|
}
|