2022-04-27 09:35:20 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-04-27 09:35:20 +00:00
|
|
|
# image metadata:
|
|
|
|
# hw_firmware_type=uefi
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
let
|
2022-04-27 09:35:20 +00:00
|
|
|
inherit (lib) mkIf mkDefault;
|
|
|
|
cfg = config.openstack;
|
2020-11-21 19:51:51 +00:00
|
|
|
metadataFetcher = import ./openstack-metadata-fetcher.nix {
|
2020-04-24 23:36:52 +00:00
|
|
|
targetRoot = "/";
|
|
|
|
wgetExtraOptions = "--retry-connrefused";
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
imports = [
|
|
|
|
../profiles/qemu-guest.nix
|
2022-04-27 09:35:20 +00:00
|
|
|
|
|
|
|
# Note: While we do use the headless profile, we also explicitly
|
|
|
|
# turn on the serial console on tty1 below.
|
|
|
|
# Note that I could not find any documentation indicating tty1 was
|
|
|
|
# the correct choice. I picked tty1 because that is what one
|
|
|
|
# particular host was using.
|
2020-04-24 23:36:52 +00:00
|
|
|
../profiles/headless.nix
|
2022-04-27 09:35:20 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
# The Openstack Metadata service exposes data on an EC2 API also.
|
|
|
|
./ec2-data.nix
|
|
|
|
./amazon-init.nix
|
|
|
|
];
|
|
|
|
|
|
|
|
config = {
|
2022-04-27 09:35:20 +00:00
|
|
|
fileSystems."/" = mkIf (!cfg.zfs.enable) {
|
2020-04-24 23:36:52 +00:00
|
|
|
device = "/dev/disk/by-label/nixos";
|
|
|
|
fsType = "ext4";
|
|
|
|
autoResize = true;
|
|
|
|
};
|
|
|
|
|
2022-04-27 09:35:20 +00: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.
|
|
|
|
device = "/dev/disk/by-label/ESP";
|
|
|
|
fsType = "vfat";
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
boot.growPartition = true;
|
2022-04-27 09:35:20 +00:00
|
|
|
boot.kernelParams = [ "console=tty1" ];
|
|
|
|
boot.loader.grub.device = if (!cfg.efi) then "/dev/vda" else "nodev";
|
|
|
|
boot.loader.grub.efiSupport = cfg.efi;
|
|
|
|
boot.loader.grub.efiInstallAsRemovable = cfg.efi;
|
|
|
|
boot.loader.timeout = 1;
|
|
|
|
boot.loader.grub.extraConfig = ''
|
|
|
|
serial --unit=1 --speed=115200 --word=8 --parity=no --stop=1
|
|
|
|
terminal_output console serial
|
|
|
|
terminal_input console serial
|
|
|
|
'';
|
|
|
|
|
|
|
|
services.zfs.expandOnBoot = mkIf cfg.zfs.enable (lib.mkDefault "all");
|
|
|
|
boot.zfs.devNodes = mkIf cfg.zfs.enable "/dev/";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
# Allow root logins
|
|
|
|
services.openssh = {
|
|
|
|
enable = true;
|
2023-01-20 10:41:00 +00:00
|
|
|
settings.PermitRootLogin = "prohibit-password";
|
|
|
|
settings.PasswordAuthentication = mkDefault false;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2022-04-27 09:35:20 +00:00
|
|
|
# Enable the serial console on tty1
|
|
|
|
systemd.services."serial-getty@tty1".enable = true;
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
# Force getting the hostname from Openstack metadata.
|
|
|
|
networking.hostName = mkDefault "";
|
|
|
|
|
|
|
|
systemd.services.openstack-init = {
|
|
|
|
path = [ pkgs.wget ];
|
|
|
|
description = "Fetch Metadata on startup";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2022-04-27 09:35:20 +00:00
|
|
|
before = [ "apply-ec2-data.service" "amazon-init.service" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
wants = [ "network-online.target" ];
|
|
|
|
after = [ "network-online.target" ];
|
|
|
|
script = metadataFetcher;
|
|
|
|
restartIfChanged = false;
|
|
|
|
unitConfig.X-StopOnRemoval = false;
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
RemainAfterExit = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|