2015-05-16 23:22:35 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
2016-12-09 10:48:54 +01:00
|
|
|
inherit (lib) mkEnableOption mkIf mkOption types;
|
|
|
|
|
|
|
|
generic = variant:
|
|
|
|
let
|
|
|
|
cfg = config.services.${variant};
|
|
|
|
pkg = pkgs.${variant};
|
2018-02-11 23:28:00 +01:00
|
|
|
birdBin = if variant == "bird6" then "bird6" else "bird";
|
2016-12-09 10:48:54 +01:00
|
|
|
birdc = if variant == "bird6" then "birdc6" else "birdc";
|
2018-02-11 23:28:00 +01:00
|
|
|
descr =
|
|
|
|
{ bird = "1.9.x with IPv4 suport";
|
|
|
|
bird6 = "1.9.x with IPv6 suport";
|
|
|
|
bird2 = "2.x";
|
|
|
|
}.${variant};
|
2016-12-09 10:48:54 +01:00
|
|
|
configFile = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "${variant}.conf";
|
|
|
|
text = cfg.config;
|
|
|
|
preferLocalBuild = true;
|
|
|
|
buildCommand = ''
|
|
|
|
echo -n "$text" > $out
|
2018-02-11 23:28:00 +01:00
|
|
|
${pkg}/bin/${birdBin} -d -p -c $out
|
2015-05-16 23:22:35 +02:00
|
|
|
'';
|
|
|
|
};
|
2016-12-09 10:48:54 +01:00
|
|
|
in {
|
|
|
|
###### interface
|
|
|
|
options = {
|
|
|
|
services.${variant} = {
|
2018-02-11 23:28:00 +01:00
|
|
|
enable = mkEnableOption "BIRD Internet Routing Daemon (${descr})";
|
2016-12-09 10:48:54 +01:00
|
|
|
config = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
description = ''
|
|
|
|
BIRD Internet Routing Daemon configuration file.
|
|
|
|
<link xlink:href='http://bird.network.cz/'/>
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2015-05-16 23:22:35 +02:00
|
|
|
};
|
|
|
|
|
2016-12-09 10:48:54 +01:00
|
|
|
###### implementation
|
|
|
|
config = mkIf cfg.enable {
|
2016-12-28 06:35:31 +01:00
|
|
|
environment.systemPackages = [ pkg ];
|
2016-12-09 10:48:54 +01:00
|
|
|
systemd.services.${variant} = {
|
2018-02-11 23:28:00 +01:00
|
|
|
description = "BIRD Internet Routing Daemon (${descr})";
|
2016-12-09 10:48:54 +01:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2018-09-02 06:51:32 +02:00
|
|
|
reloadIfChanged = true;
|
2016-12-09 10:48:54 +01:00
|
|
|
serviceConfig = {
|
|
|
|
Type = "forking";
|
|
|
|
Restart = "on-failure";
|
2018-02-11 23:28:00 +01:00
|
|
|
ExecStart = "${pkg}/bin/${birdBin} -c ${configFile} -u ${variant} -g ${variant}";
|
2016-12-09 10:48:54 +01:00
|
|
|
ExecReload = "${pkg}/bin/${birdc} configure";
|
|
|
|
ExecStop = "${pkg}/bin/${birdc} down";
|
|
|
|
CapabilityBoundingSet = [ "CAP_CHOWN" "CAP_FOWNER" "CAP_DAC_OVERRIDE" "CAP_SETUID" "CAP_SETGID"
|
|
|
|
# see bird/sysdep/linux/syspriv.h
|
|
|
|
"CAP_NET_BIND_SERVICE" "CAP_NET_BROADCAST" "CAP_NET_ADMIN" "CAP_NET_RAW" ];
|
|
|
|
ProtectSystem = "full";
|
|
|
|
ProtectHome = "yes";
|
|
|
|
SystemCallFilter="~@cpu-emulation @debug @keyring @module @mount @obsolete @raw-io";
|
|
|
|
MemoryDenyWriteExecute = "yes";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
users = {
|
2018-06-30 01:58:35 +02:00
|
|
|
users.${variant} = {
|
2016-12-09 10:48:54 +01:00
|
|
|
description = "BIRD Internet Routing Daemon user";
|
2018-02-11 23:28:00 +01:00
|
|
|
group = variant;
|
2016-12-09 10:48:54 +01:00
|
|
|
};
|
2018-06-30 01:58:35 +02:00
|
|
|
groups.${variant} = {};
|
2016-12-09 10:48:54 +01:00
|
|
|
};
|
2015-05-16 23:22:35 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-02-11 23:28:00 +01:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
imports = map generic [ "bird" "bird6" "bird2" ];
|
2015-05-16 23:22:35 +02:00
|
|
|
}
|