From ad4a70ffa1fd622d23cc54e4172b53377cf8f15e Mon Sep 17 00:00:00 2001 From: Lillian-Violet Date: Sat, 2 Mar 2024 23:15:23 +0100 Subject: [PATCH] Add contabo wan for ipv6 support --- flake.nix | 7 +++ modules/home-manager/default.nix | 5 +++ modules/nixos/contabo/wan/default.nix | 65 +++++++++++++++++++++++++++ modules/nixos/default.nix | 6 +++ nixos/hosts/queen/configuration.nix | 12 +++++ 5 files changed, 95 insertions(+) create mode 100644 modules/home-manager/default.nix create mode 100644 modules/nixos/contabo/wan/default.nix create mode 100644 modules/nixos/default.nix diff --git a/flake.nix b/flake.nix index 08456d5..5a3b753 100644 --- a/flake.nix +++ b/flake.nix @@ -95,6 +95,13 @@ # Other options beside 'alejandra' include 'nixpkgs-fmt' formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.alejandra); + # Reusable nixos modules you might want to export + # These are usually stuff you would upstream into nixpkgs + nixosModules = import ./modules/nixos; + # Reusable home-manager modules you might want to export + # These are usually stuff you would upstream into home-manager + homeManagerModules = import ./modules/home-manager; + # Your custom packages and modifications, exported as overlays overlays = import ./overlays {inherit inputs;}; diff --git a/modules/home-manager/default.nix b/modules/home-manager/default.nix new file mode 100644 index 0000000..c682b92 --- /dev/null +++ b/modules/home-manager/default.nix @@ -0,0 +1,5 @@ +# Add your reusable NixOS modules to this directory, on their own file (https://nixos.wiki/wiki/Module). +# These should be stuff you would like to share with others, not your personal configurations. +{ + # List your module files here +} diff --git a/modules/nixos/contabo/wan/default.nix b/modules/nixos/contabo/wan/default.nix new file mode 100644 index 0000000..785ea9b --- /dev/null +++ b/modules/nixos/contabo/wan/default.nix @@ -0,0 +1,65 @@ +{ + lib, + config, + ... +}: +with lib; let + cfg = config.modules.contabo.wan; +in { + options.modules.contabo.wan = { + enable = mkEnableOption "Enable Contabo Cloud WAN interface configuration"; + + macAddress = mkOption { + type = types.str; + description = "MAC Address of the WAN interface"; + }; + + ipAddresses = mkOption { + type = types.listOf types.str; + description = "List of IP Addresses on the WAN interface"; + }; + }; + + config = mkIf cfg.enable { + systemd.network.networks."20-wan" = { + matchConfig = { + MACAddress = cfg.macAddress; + }; + address = cfg.ipAddresses; + routes = [ + {routeConfig.Gateway = "fe80::1";} + {routeConfig = {Destination = "172.31.1.1";};} + { + routeConfig = { + Gateway = "172.31.1.1"; + GatewayOnLink = true; + }; + } + { + routeConfig = { + Destination = "172.16.0.0/12"; + Type = "unreachable"; + }; + } + { + routeConfig = { + Destination = "192.168.0.0/16"; + Type = "unreachable"; + }; + } + { + routeConfig = { + Destination = "10.0.0.0/8"; + Type = "unreachable"; + }; + } + { + routeConfig = { + Destination = "fc00::/7"; + Type = "unreachable"; + }; + } + ]; + }; + }; +} diff --git a/modules/nixos/default.nix b/modules/nixos/default.nix new file mode 100644 index 0000000..8685807 --- /dev/null +++ b/modules/nixos/default.nix @@ -0,0 +1,6 @@ +# Add your reusable NixOS modules to this directory, on their own file (https://nixos.wiki/wiki/Module). +# These should be stuff you would like to share with others, not your personal configurations. +{ + # List your module files here + contabo.wan = import ./contabo/wan; +} diff --git a/nixos/hosts/queen/configuration.nix b/nixos/hosts/queen/configuration.nix index aa89f8d..c313726 100644 --- a/nixos/hosts/queen/configuration.nix +++ b/nixos/hosts/queen/configuration.nix @@ -10,6 +10,7 @@ imports = [ # If you want to use modules your own flake exports (from modules/home-manager): # outputs.homeManagerModules.example + outputs.nixosModules.contabo.wan inputs.home-manager.nixosModules.home-manager # Or modules exported from other flakes (such as nix-colors): # inputs.nix-colors.homeManagerModules.default @@ -121,6 +122,17 @@ networking.firewall.allowedTCPPorts = [22 80 443]; + networking.useNetworkd = true; + + modules.contabo.wan = { + enable = true; + macAddress = "aa:bb:cc:dd:ee:ff"; # changeme + ipAddresses = [ + "192.0.2.0/32" + "2001:db8::1/64" + ]; + }; + # Set your time zone. time.timeZone = "Europe/Amsterdam";