clan-infra/modules/initrd-networking.nix

73 lines
1.7 KiB
Nix
Raw Normal View History

2023-07-17 08:31:59 +00:00
{ config
, lib
, ...
}:
with lib; let
cfg = config.clan.networking;
in
{
options = {
clan.networking.ipv4.address = mkOption {
type = types.str;
};
clan.networking.ipv4.cidr = mkOption {
type = types.str;
default = "26";
};
clan.networking.ipv4.gateway = mkOption {
type = types.str;
};
clan.networking.ipv6.address = mkOption {
type = types.str;
};
clan.networking.ipv6.cidr = mkOption {
type = types.str;
default = "64";
};
};
config = {
# Hack so that network is considered up by boot.initrd.network and postCommands gets executed.
boot.kernelParams = [ "ip=127.0.0.1:::::lo:none" ];
2023-11-29 12:53:31 +00:00
boot.initrd.systemd.enable = false;
2023-07-17 08:31:59 +00:00
boot.initrd.network = {
enable = true;
ssh = {
enable = true;
port = 2222;
hostKeys = [
# not using sops here because we cannot reliable deploy this secret
#config.sops.secrets.initrd-ssh-key.path
"/var/lib/secrets/initrd_ssh_key"
];
authorizedKeys = config.users.users.root.openssh.authorizedKeys.keys;
};
postCommands = ''
2023-11-29 12:53:31 +00:00
ip addr
ip link set dev enp6s0 up
2023-07-17 08:31:59 +00:00
2023-11-29 12:53:31 +00:00
ip addr add ${cfg.ipv4.address}/${cfg.ipv4.cidr} dev enp6s0
ip route add ${cfg.ipv4.gateway} dev enp6s0
ip route add default via ${cfg.ipv4.gateway} dev enp6s0
2023-07-17 08:31:59 +00:00
2023-11-29 12:53:31 +00:00
ip -6 addr add ${cfg.ipv6.address}/${cfg.ipv6.cidr} dev enp6s0
ip -6 route add default via fe80::1 dev enp6s0
2023-07-17 08:31:59 +00:00
'';
};
boot.initrd.kernelModules = [
"e1000e" # older hetzner machines, 1 GbE nics
"igc" # newer herzner machines, 2.5 GbE nics
2023-09-05 14:57:03 +00:00
"igb"
2023-07-17 08:31:59 +00:00
# for debugging installation in vms
"virtio_pci"
"virtio_net"
];
};
}