Serge Bazanski | cc769a5 | 2021-02-13 13:13:41 +0100 | [diff] [blame] | 1 | # Support for GRETap interfaces in NixOS' scripted networking. |
| 2 | # |
| 3 | # We currently only use it in the edge01.waw test framework to bring vlans |
| 4 | # across test VMs. |
| 5 | |
| 6 | { config, pkgs, lib, ... }: |
| 7 | |
| 8 | with lib; |
| 9 | |
| 10 | let |
| 11 | cfg = config.hscloud.gretap; |
| 12 | |
| 13 | in { |
| 14 | options.hscloud.gretap = { |
| 15 | interfaces = mkOption { |
| 16 | type = with types; attrsOf (submodule { |
| 17 | options = { |
| 18 | localV4 = mkOption { |
| 19 | type = types.str; |
| 20 | description = "Local outer IPv4 address"; |
| 21 | }; |
| 22 | remoteV4 = mkOption { |
| 23 | type = types.str; |
| 24 | description = "Remote outer IPv4 address"; |
| 25 | }; |
| 26 | id = mkOption { |
| 27 | type = types.int; |
| 28 | description = "Tunnel ID"; |
| 29 | }; |
| 30 | parent = mkOption { |
| 31 | type = types.str; |
| 32 | description = "Parent/outer device"; |
| 33 | }; |
| 34 | }; |
| 35 | }); |
| 36 | description = '' |
| 37 | GRETap interfaces to create. |
| 38 | ''; |
| 39 | }; |
| 40 | }; |
| 41 | |
| 42 | config.boot.kernelModules = [ "fou" ]; |
| 43 | config.systemd.services = mapAttrs' (name: value: nameValuePair "${name}-gretap" { |
Serge Bazanski | 957d911 | 2022-06-12 12:26:02 +0200 | [diff] [blame] | 44 | wants = if config.networking.useNetworkd then [ |
| 45 | "systemd-networkd.service" |
| 46 | ] else [ |
Serge Bazanski | cc769a5 | 2021-02-13 13:13:41 +0100 | [diff] [blame] | 47 | "${name}-netdev.service" |
| 48 | "network-addresses-${value.parent}.service" |
| 49 | ]; |
Serge Bazanski | 957d911 | 2022-06-12 12:26:02 +0200 | [diff] [blame] | 50 | after = if config.networking.useNetworkd then [ |
| 51 | "systemd-networkd.service" |
| 52 | ] else [ |
Serge Bazanski | cc769a5 | 2021-02-13 13:13:41 +0100 | [diff] [blame] | 53 | "network-addresses-${value.parent}.service" |
| 54 | ]; |
Serge Bazanski | 957d911 | 2022-06-12 12:26:02 +0200 | [diff] [blame] | 55 | before = if config.networking.useNetworkd then [] else [ |
Serge Bazanski | cc769a5 | 2021-02-13 13:13:41 +0100 | [diff] [blame] | 56 | "network-addresses-${name}.service" |
| 57 | ]; |
Serge Bazanski | 957d911 | 2022-06-12 12:26:02 +0200 | [diff] [blame] | 58 | wantedBy = if config.networking.useNetworkd then [ |
| 59 | "network-online.target" |
| 60 | ] else [ |
Serge Bazanski | cc769a5 | 2021-02-13 13:13:41 +0100 | [diff] [blame] | 61 | "network-addresses-${name}.service" |
| 62 | ]; |
| 63 | serviceConfig = { |
| 64 | Type = "oneshot"; |
Serge Bazanski | 957d911 | 2022-06-12 12:26:02 +0200 | [diff] [blame] | 65 | ExecStart = "${pkgs.iproute2}/bin/ip link add name ${name} type gretap remote ${value.remoteV4} local ${value.localV4} key ${toString value.id}"; |
Serge Bazanski | cc769a5 | 2021-02-13 13:13:41 +0100 | [diff] [blame] | 66 | }; |
| 67 | }) cfg.interfaces; |
| 68 | } |