Skip to content

Commit

Permalink
hcloud: add mgit.hcloud.auto-network option
Browse files Browse the repository at this point in the history
  • Loading branch information
mkg20001 committed Jul 12, 2024
1 parent addb934 commit 042f28e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 18 deletions.
39 changes: 33 additions & 6 deletions os/hcloud/configuration.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
disko: { inputs, modulesPath, ... }:
disko: { inputs, modulesPath, config, lib, ... }: with lib;
{
imports = [
(modulesPath + "/profiles/qemu-guest.nix")
Expand All @@ -10,10 +10,37 @@ disko: { inputs, modulesPath, ... }:
})
];

# boot.loader.grub.device = "/dev/sda";
boot.initrd.availableKernelModules = [ "ata_piix" "uhci_hcd" "xen_blkfront" "vmw_pvscsi" ];
boot.initrd.kernelModules = [ "nvme" ];
options = {
mgit.hcloud.auto-network = mkOption {
type = types.nullOr types.str;
default = null;
description = "Hetzner cloud network autosetup. Specifiy IPv6 address here to enable.";
};
};

boot.tmp.cleanOnBoot = true;
boot.growPartition = true;
config = mkMerge [
{
# boot.loader.grub.device = "/dev/sda";
boot.initrd.availableKernelModules = [ "ata_piix" "uhci_hcd" "xen_blkfront" "vmw_pvscsi" ];
boot.initrd.kernelModules = [ "nvme" ];

boot.tmp.cleanOnBoot = true;
boot.growPartition = true;
}
(mkIf (config.mgit.hcloud.auto-network != null) {
networking.usePredictableInterfaceNames = false;

systemd.network.enable = true;
systemd.network.networks."10-wan" = {
matchConfig.Name = "eth0";
networkConfig.DHCP = "ipv4";
address = [
"${config.mgit.hcloud.auto-network}"
];
routes = [
{ routeConfig.Gateway = "fe80::1"; }
];
};
})
];
}
14 changes: 2 additions & 12 deletions template/nixos/hosts/example-hcloud/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,8 @@ with lib;
inputs.common.nixosModules.hcloud_base
];

systemd.network.enable = true;
systemd.network.networks."10-wan" = {
matchConfig.Name = "ens3"; # either ens3 (amd64) or enp1s0 (arm64)
networkConfig.DHCP = "ipv4";
address = [
# replace this address with the one assigned to your instance
"2a01:4f8:aaaa:bbbb::2/64"
];
routes = [
{ routeConfig.Gateway = "fe80::1"; }
];
};
# replace this address with the one assigned to your instance
mgit.hcloud.auto-network = "2a01:4f8:aaaa:bbbb::2/64";

networking.hostName = "example-hcloud";
system.stateVersion = "24.05";
Expand Down
6 changes: 6 additions & 0 deletions template/nixos/hosts/example-physical/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,20 @@ with lib;
})
];

# Use this to rename enpXXX back to eth0 (optional):
# networking.usePredictableInterfaceNames = false;

# Network.
systemd.network = {
enable = true;
# Substitute with machine's interface name.
networks."40-enp195s0" = {
matchConfig = {
Name = "enp195s0";
};
gateway = [ "fe80::1" "1.2.3.99" ];
networkConfig = {
# Substitute machine's your address.
Address = "2a01:4f8:aaaa:bbbb::2/128";
};
addresses = [
Expand All @@ -34,6 +39,7 @@ with lib;
};
};

# Demonstration of firewall, adjust to your needs.
networking.firewall = {
allowedTCPPorts = [ 80 443 ];
allowedUDPPorts = [ 443 ];
Expand Down

0 comments on commit 042f28e

Please sign in to comment.