blob: f28d64c1c3c8b582eb1b8d417b28c1cea4799757 [file] [log] [blame]
Serge Bazanskicc769a52021-02-13 13:13:41 +01001# 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
8with lib;
9
10let
11 cfg = config.hscloud.gretap;
12
13in {
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 Bazanski957d9112022-06-12 12:26:02 +020044 wants = if config.networking.useNetworkd then [
45 "systemd-networkd.service"
46 ] else [
Serge Bazanskicc769a52021-02-13 13:13:41 +010047 "${name}-netdev.service"
48 "network-addresses-${value.parent}.service"
49 ];
Serge Bazanski957d9112022-06-12 12:26:02 +020050 after = if config.networking.useNetworkd then [
51 "systemd-networkd.service"
52 ] else [
Serge Bazanskicc769a52021-02-13 13:13:41 +010053 "network-addresses-${value.parent}.service"
54 ];
Serge Bazanski957d9112022-06-12 12:26:02 +020055 before = if config.networking.useNetworkd then [] else [
Serge Bazanskicc769a52021-02-13 13:13:41 +010056 "network-addresses-${name}.service"
57 ];
Serge Bazanski957d9112022-06-12 12:26:02 +020058 wantedBy = if config.networking.useNetworkd then [
59 "network-online.target"
60 ] else [
Serge Bazanskicc769a52021-02-13 13:13:41 +010061 "network-addresses-${name}.service"
62 ];
63 serviceConfig = {
64 Type = "oneshot";
Serge Bazanski957d9112022-06-12 12:26:02 +020065 ExecStart = "${pkgs.iproute2}/bin/ip link add name ${name} type gretap remote ${value.remoteV4} local ${value.localV4} key ${toString value.id}";
Serge Bazanskicc769a52021-02-13 13:13:41 +010066 };
67 }) cfg.interfaces;
68}