3
0
Fork 0
forked from mirrors/nixpkgs
nixpkgs/nixos/modules/services/networking/gvpe.nix
pennae 2e751c0772 treewide: automatically md-convert option descriptions
the conversion procedure is simple:

 - find all things that look like options, ie calls to either `mkOption`
   or `lib.mkOption` that take an attrset. remember the attrset as the
   option
 - for all options, find a `description` attribute who's value is not a
   call to `mdDoc` or `lib.mdDoc`
 - textually convert the entire value of the attribute to MD with a few
   simple regexes (the set from mdize-module.sh)
 - if the change produced a change in the manual output, discard
 - if the change kept the manual unchanged, add some text to the
   description to make sure we've actually found an option. if the
   manual changes this time, keep the converted description

this procedure converts 80% of nixos options to markdown. around 2000
options remain to be inspected, but most of those fail the "does not
change the manual output check": currently the MD conversion process
does not faithfully convert docbook tags like <code> and <package>, so
any option using such tags will not be converted at all.
2022-07-30 15:16:34 +02:00

131 lines
3.2 KiB
Nix

# GNU Virtual Private Ethernet
{config, pkgs, lib, ...}:
let
inherit (lib) mkOption mkIf types;
cfg = config.services.gvpe;
finalConfig = if cfg.configFile != null then
cfg.configFile
else if cfg.configText != null then
pkgs.writeTextFile {
name = "gvpe.conf";
text = cfg.configText;
}
else
throw "You must either specify contents of the config file or the config file itself for GVPE";
ifupScript = if cfg.ipAddress == null || cfg.subnet == null then
throw "Specify IP address and subnet (with mask) for GVPE"
else if cfg.nodename == null then
throw "You must set node name for GVPE"
else
(pkgs.writeTextFile {
name = "gvpe-if-up";
text = ''
#! /bin/sh
export PATH=$PATH:${pkgs.iproute2}/sbin
ip link set $IFNAME up
ip address add ${cfg.ipAddress} dev $IFNAME
ip route add ${cfg.subnet} dev $IFNAME
${cfg.customIFSetup}
'';
executable = true;
});
in
{
options = {
services.gvpe = {
enable = lib.mkEnableOption "gvpe";
nodename = mkOption {
default = null;
type = types.nullOr types.str;
description =lib.mdDoc ''
GVPE node name
'';
};
configText = mkOption {
default = null;
type = types.nullOr types.lines;
example = ''
tcp-port = 655
udp-port = 655
mtu = 1480
ifname = vpn0
node = alpha
hostname = alpha.example.org
connect = always
enable-udp = true
enable-tcp = true
on alpha if-up = if-up-0
on alpha pid-file = /var/gvpe/gvpe.pid
'';
description = lib.mdDoc ''
GVPE config contents
'';
};
configFile = mkOption {
default = null;
type = types.nullOr types.path;
example = "/root/my-gvpe-conf";
description = lib.mdDoc ''
GVPE config file, if already present
'';
};
ipAddress = mkOption {
default = null;
type = types.nullOr types.str;
description = lib.mdDoc ''
IP address to assign to GVPE interface
'';
};
subnet = mkOption {
default = null;
type = types.nullOr types.str;
example = "10.0.0.0/8";
description = lib.mdDoc ''
IP subnet assigned to GVPE network
'';
};
customIFSetup = mkOption {
default = "";
type = types.lines;
description = lib.mdDoc ''
Additional commands to apply in ifup script
'';
};
};
};
config = mkIf cfg.enable {
systemd.services.gvpe = {
description = "GNU Virtual Private Ethernet node";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
preStart = ''
mkdir -p /var/gvpe
mkdir -p /var/gvpe/pubkey
chown root /var/gvpe
chmod 700 /var/gvpe
cp ${finalConfig} /var/gvpe/gvpe.conf
cp ${ifupScript} /var/gvpe/if-up
'';
script = "${pkgs.gvpe}/sbin/gvpe -c /var/gvpe -D ${cfg.nodename} "
+ " ${cfg.nodename}.pid-file=/var/gvpe/gvpe.pid"
+ " ${cfg.nodename}.if-up=if-up"
+ " &> /var/log/gvpe";
serviceConfig.Restart = "always";
};
};
}