···
config = mkIf (cfg.networks != { }) (
-
etcConfig = foldr (a: b: a // b) { }
-
(flip mapAttrsToList cfg.networks (network: data:
-
flip mapAttrs' data.hosts (host: text: nameValuePair
-
("tinc/${network}/hosts/${host}")
-
({ mode = "0644"; user = "tinc.${network}"; inherit text; })
-
"tinc/${network}/tinc.conf" = {
-
${toTincConf ({ Interface = "tinc.${network}"; } // data.settings)}
-
environment.etc = etcConfig;
-
systemd.services = flip mapAttrs' cfg.networks (network: data: nameValuePair
-
(let version = getVersion data.package; in {
-
description = "Tinc Daemon - ${network}";
-
wantedBy = [ "multi-user.target" ];
-
path = [ data.package ];
-
reloadTriggers = mkIf (versionAtLeast version "1.1pre") [ (builtins.toJSON etcConfig) ];
-
restartTriggers = mkIf (versionOlder version "1.1pre") [ (builtins.toJSON etcConfig) ];
-
ExecReload = mkIf (versionAtLeast version "1.1pre") "${data.package}/bin/tinc -n ${network} reload";
-
ExecStart = "${data.package}/bin/tincd -D -U tinc.${network} -n ${network} ${optionalString (data.chroot) "-R"} --pidfile /run/tinc.${network}.pid -d ${toString data.debugLevel}";
-
mkdir -p /etc/tinc/${network}/hosts
-
chown tinc.${network} /etc/tinc/${network}/hosts
-
mkdir -p /etc/tinc/${network}/invitations
-
chown tinc.${network} /etc/tinc/${network}/invitations
-
# Determine how we should generate our keys
-
if type tinc >/dev/null 2>&1; then
-
# Tinc 1.1+ uses the tinc helper application for key generation
-
${if data.ed25519PrivateKeyFile != null then " # ed25519 Keyfile managed by nix" else ''
-
# Prefer ED25519 keys (only in 1.1+)
-
[ -f "/etc/tinc/${network}/ed25519_key.priv" ] || tinc -n ${network} generate-ed25519-keys
-
${if data.rsaPrivateKeyFile != null then " # RSA Keyfile managed by nix" else ''
-
[ -f "/etc/tinc/${network}/rsa_key.priv" ] || tinc -n ${network} generate-rsa-keys 4096
-
# In case there isn't anything to do
-
# Tinc 1.0 uses the tincd application
-
[ -f "/etc/tinc/${network}/rsa_key.priv" ] || tincd -n ${network} -K 4096
-
environment.systemPackages = let
-
cli-wrappers = pkgs.stdenv.mkDerivation {
-
name = "tinc-cli-wrappers";
-
nativeBuildInputs = [ pkgs.makeWrapper ];
-
${concatStringsSep "\n" (mapAttrsToList (network: data:
-
optionalString (versionAtLeast data.package.version "1.1pre") ''
-
makeWrapper ${data.package}/bin/tinc "$out/bin/tinc.${network}" \
-
--add-flags "--pidfile=/run/tinc.${network}.pid" \
-
--add-flags "--config=/etc/tinc/${network}"
-
users.users = flip mapAttrs' cfg.networks (network: _:
-
nameValuePair ("tinc.${network}") ({
-
description = "Tinc daemon user for ${network}";
-
group = "tinc.${network}";
-
users.groups = flip mapAttrs' cfg.networks (network: _:
-
nameValuePair "tinc.${network}" {}
meta.maintainers = with maintainers; [ minijackson mic92 ];