1 # GNU Virtual Private Ethernet
11 inherit (lib) mkOption mkIf types;
13 cfg = config.services.gvpe;
16 if cfg.configFile != null then
18 else if cfg.configText != null then
21 text = cfg.configText;
24 throw "You must either specify contents of the config file or the config file itself for GVPE";
27 if cfg.ipAddress == null || cfg.subnet == null then
28 throw "Specify IP address and subnet (with mask) for GVPE"
29 else if cfg.nodename == null then
30 throw "You must set node name for GVPE"
37 export PATH=$PATH:${pkgs.iproute2}/sbin
39 ip link set dev $IFNAME up
40 ip address add ${cfg.ipAddress} dev $IFNAME
41 ip route add ${cfg.subnet} dev $IFNAME
52 enable = lib.mkEnableOption "gvpe";
56 type = types.nullOr types.str;
61 configText = mkOption {
63 type = types.nullOr types.lines;
71 hostname = alpha.example.org
75 on alpha if-up = if-up-0
76 on alpha pid-file = /var/gvpe/gvpe.pid
82 configFile = mkOption {
84 type = types.nullOr types.path;
85 example = "/root/my-gvpe-conf";
87 GVPE config file, if already present
90 ipAddress = mkOption {
92 type = types.nullOr types.str;
94 IP address to assign to GVPE interface
99 type = types.nullOr types.str;
100 example = "10.0.0.0/8";
102 IP subnet assigned to GVPE network
105 customIFSetup = mkOption {
109 Additional commands to apply in ifup script
114 config = mkIf cfg.enable {
115 systemd.services.gvpe = {
116 description = "GNU Virtual Private Ethernet node";
117 after = [ "network.target" ];
118 wantedBy = [ "multi-user.target" ];
122 mkdir -p /var/gvpe/pubkey
125 cp ${finalConfig} /var/gvpe/gvpe.conf
126 cp ${ifupScript} /var/gvpe/if-up
130 "${pkgs.gvpe}/sbin/gvpe -c /var/gvpe -D ${cfg.nodename} "
131 + " ${cfg.nodename}.pid-file=/var/gvpe/gvpe.pid"
132 + " ${cfg.nodename}.if-up=if-up"
133 + " &> /var/log/gvpe";
135 serviceConfig.Restart = "always";