machines/nix/modules/nixos/hetzner/default.nix
Kaare Hoff Skovgaard 1945038c90
Some checks failed
/ dev-shell (push) Successful in 19s
/ check (push) Failing after 18s
/ terraform-providers (push) Successful in 30s
/ rust-packages (push) Successful in 39s
First PoC on provisioning instance end to end on openstack
2025-07-08 16:08:37 +02:00

77 lines
2 KiB
Nix

{
config,
lib,
pkgs,
system,
...
}:
let
cfg = config.khscodes.hetzner;
in
{
options.khscodes.hetzner = {
enable = lib.mkEnableOption "Enables the machine as a hetzner machine";
diskName = lib.mkOption {
type = lib.types.str;
default = "nixos";
description = "Name of the root disk device";
};
metadataApiUri = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = "Sets the metadata API url that the server will contact to gather metadata information from. Should probably only be used for testing";
};
};
config = lib.mkIf cfg.enable {
disko = lib.khscodes.disko-root-lvm-uefi {
device = "/dev/sda";
diskName = cfg.diskName;
};
boot.tmp.cleanOnBoot = lib.mkDefault true;
boot.initrd.kernelModules = lib.mkIf (system == "aarch64-linux") [ "virtio_gpu" ];
boot.kernelParams = lib.mkIf (system == "aarch64-linux") [ "console=tty" ];
zramSwap.enable = lib.mkDefault true;
khscodes.systemd-boot.enable = lib.mkDefault true;
khscodes.qemu-guest.enable = true;
networking = {
useDHCP = false;
useNetworkd = false;
};
systemd.network = {
enable = true;
networks."10-enp1s0" = {
matchConfig.Name = [
"eth0"
"enp1s0"
];
networkConfig = {
DHCP = "ipv4";
};
linkConfig.RequiredForOnline = "routable";
};
};
systemd.services.hetzner-static-ip = {
enable = true;
wants = [ "network-online.target" ];
after = [ "network-online.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
ExecStart = ''
${lib.getExe pkgs.khscodes.hetzner-static-ip} configure
'';
};
environment =
{
PATH = lib.mkForce "";
}
// lib.attrsets.optionalAttrs (cfg.metadataApiUri != null) {
INSTANCE_API_URI = cfg.metadataApiUri;
};
};
};
}