1 # GNU Virtual Private Ethernet
3 {config, pkgs, lib, ...}:
6 inherit (lib) mkOption mkIf types;
8 cfg = config.services.gvpe;
10 finalConfig = if cfg.configFile != null then
12 else if cfg.configText != null then
15 text = cfg.configText;
18 throw "You must either specify contents of the config file or the config file itself for GVPE";
20 ifupScript = if cfg.ipAddress == null || cfg.subnet == null then
21 throw "Specify IP address and subnet (with mask) for GVPE"
22 else if cfg.nodename == null then
23 throw "You must set node name for GVPE"
30 export PATH=$PATH:${pkgs.iproute2}/sbin
32 ip link set dev $IFNAME up
33 ip address add ${cfg.ipAddress} dev $IFNAME
34 ip route add ${cfg.subnet} dev $IFNAME
45 enable = lib.mkEnableOption "gvpe";
49 type = types.nullOr types.str;
54 configText = mkOption {
56 type = types.nullOr types.lines;
64 hostname = alpha.example.org
68 on alpha if-up = if-up-0
69 on alpha pid-file = /var/gvpe/gvpe.pid
75 configFile = mkOption {
77 type = types.nullOr types.path;
78 example = "/root/my-gvpe-conf";
80 GVPE config file, if already present
83 ipAddress = mkOption {
85 type = types.nullOr types.str;
87 IP address to assign to GVPE interface
92 type = types.nullOr types.str;
93 example = "10.0.0.0/8";
95 IP subnet assigned to GVPE network
98 customIFSetup = mkOption {
102 Additional commands to apply in ifup script
107 config = mkIf cfg.enable {
108 systemd.services.gvpe = {
109 description = "GNU Virtual Private Ethernet node";
110 after = [ "network.target" ];
111 wantedBy = [ "multi-user.target" ];
115 mkdir -p /var/gvpe/pubkey
118 cp ${finalConfig} /var/gvpe/gvpe.conf
119 cp ${ifupScript} /var/gvpe/if-up
122 script = "${pkgs.gvpe}/sbin/gvpe -c /var/gvpe -D ${cfg.nodename} "
123 + " ${cfg.nodename}.pid-file=/var/gvpe/gvpe.pid"
124 + " ${cfg.nodename}.if-up=if-up"
125 + " &> /var/log/gvpe";
127 serviceConfig.Restart = "always";