2022-02-03 16:05:52 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
2017-02-24 21:17:52 +00:00
|
|
|
|
2022-03-08 14:26:44 +00:00
|
|
|
# image metadata:
|
|
|
|
# hw_firmware_type=uefi
|
|
|
|
|
2019-02-06 11:16:22 +00:00
|
|
|
let
|
2022-02-03 16:05:52 +00:00
|
|
|
inherit (lib) mkIf mkDefault;
|
|
|
|
cfg = config.openstack;
|
2020-11-18 16:42:32 +00:00
|
|
|
metadataFetcher = import ./openstack-metadata-fetcher.nix {
|
2019-02-06 11:16:22 +00:00
|
|
|
targetRoot = "/";
|
|
|
|
wgetExtraOptions = "--retry-connrefused";
|
|
|
|
};
|
|
|
|
in
|
2017-02-24 21:17:52 +00:00
|
|
|
{
|
|
|
|
imports = [
|
|
|
|
../profiles/qemu-guest.nix
|
2022-03-24 15:58:54 +00:00
|
|
|
|
|
|
|
# Note: While we do use the headless profile, we also explicitly
|
2022-03-08 14:22:38 +00:00
|
|
|
# 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.
|
2017-02-24 21:17:52 +00:00
|
|
|
../profiles/headless.nix
|
2022-03-24 15:58:54 +00:00
|
|
|
|
2019-01-28 10:59:18 +00:00
|
|
|
# The Openstack Metadata service exposes data on an EC2 API also.
|
|
|
|
./ec2-data.nix
|
2019-01-28 13:44:41 +00:00
|
|
|
./amazon-init.nix
|
2017-02-24 21:17:52 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
config = {
|
2022-02-03 16:05:52 +00:00
|
|
|
fileSystems."/" = mkIf (!cfg.zfs.enable) {
|
2017-02-24 21:19:53 +00:00
|
|
|
device = "/dev/disk/by-label/nixos";
|
2019-03-21 09:04:07 +00:00
|
|
|
fsType = "ext4";
|
2017-02-24 21:19:53 +00:00
|
|
|
autoResize = true;
|
|
|
|
};
|
|
|
|
|
2022-02-03 16:05:52 +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";
|
|
|
|
};
|
|
|
|
|
2018-01-06 13:52:51 +00:00
|
|
|
boot.growPartition = true;
|
2022-03-08 14:22:38 +00:00
|
|
|
boot.kernelParams = [ "console=tty1" ];
|
2022-02-03 16:05:52 +00:00
|
|
|
boot.loader.grub.device = if (!cfg.efi) then "/dev/vda" else "nodev";
|
|
|
|
boot.loader.grub.efiSupport = cfg.efi;
|
|
|
|
boot.loader.grub.efiInstallAsRemovable = cfg.efi;
|
2022-03-24 15:58:54 +00:00
|
|
|
boot.loader.timeout = 1;
|
|
|
|
boot.loader.grub.extraConfig = ''
|
2022-03-08 14:22:38 +00:00
|
|
|
serial --unit=1 --speed=115200 --word=8 --parity=no --stop=1
|
2022-03-24 15:58:54 +00:00
|
|
|
terminal_output console serial
|
|
|
|
terminal_input console serial
|
|
|
|
'';
|
2022-02-03 16:05:52 +00:00
|
|
|
|
2022-03-08 14:26:05 +00:00
|
|
|
services.zfs.expandOnBoot = mkIf cfg.zfs.enable (lib.mkDefault "all");
|
2022-02-03 16:05:52 +00:00
|
|
|
boot.zfs.devNodes = mkIf cfg.zfs.enable "/dev/";
|
2017-02-24 21:17:52 +00:00
|
|
|
|
|
|
|
# Allow root logins
|
2017-09-11 17:33:33 +01:00
|
|
|
services.openssh = {
|
|
|
|
enable = true;
|
|
|
|
permitRootLogin = "prohibit-password";
|
|
|
|
passwordAuthentication = mkDefault false;
|
|
|
|
};
|
|
|
|
|
2022-03-24 15:58:54 +00:00
|
|
|
users.users.root.initialPassword = "foobar";
|
|
|
|
|
2022-03-08 14:22:38 +00:00
|
|
|
# Enable the serial console on tty1
|
|
|
|
systemd.services."serial-getty@tty1".enable = true;
|
2022-03-24 15:58:54 +00:00
|
|
|
|
2019-01-28 20:06:24 +00:00
|
|
|
# Force getting the hostname from Openstack metadata.
|
|
|
|
networking.hostName = mkDefault "";
|
|
|
|
|
2019-01-28 14:09:48 +00:00
|
|
|
systemd.services.openstack-init = {
|
2019-01-28 10:59:18 +00:00
|
|
|
path = [ pkgs.wget ];
|
|
|
|
description = "Fetch Metadata on startup";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2022-02-03 16:05:52 +00:00
|
|
|
before = [ "apply-ec2-data.service" "amazon-init.service" ];
|
2019-01-28 10:59:18 +00:00
|
|
|
wants = [ "network-online.target" ];
|
|
|
|
after = [ "network-online.target" ];
|
2019-02-06 11:16:22 +00:00
|
|
|
script = metadataFetcher;
|
2019-01-28 10:59:18 +00:00
|
|
|
restartIfChanged = false;
|
|
|
|
unitConfig.X-StopOnRemoval = false;
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
RemainAfterExit = true;
|
|
|
|
};
|
|
|
|
};
|
2017-02-24 21:17:52 +00:00
|
|
|
};
|
|
|
|
}
|