{ config, inputs, lib, mylib, pkgs, ... }: let host = config.krebs.build.host; net = host.nets.retiolum; keyType = "application/x-tinc-private-key; algorithm=ed25519"; keySlot = config.enstate.channels.secrets.slots."retiolum.key"; keyValidator = pkgs.writers.writeDash "validate-tinc-ed25519-private-key" '' set -efu ${pkgs.jq}/bin/jq -r -f ${pkgs.writeJq "slots-of-type.jq" '' .slots | to_entries[] | select(.value.type == $ARGS.named.type) | .key ''} --arg type ${lib.escapeShellArg keyType} "$1"/invocation.json | while read -r address; do test -e "$1"/channels/"$address" || continue ${pkgs.jq}/bin/jq -Rsc -f ${pkgs.writeJq "check-tinc-ed25519-private-key.jq" '' "-----BEGIN ED25519 PRIVATE KEY-----" as $begin | "-----END ED25519 PRIVATE KEY-----" as $end | split("\n") | if .[-1] == "" then .[:-1] else . end | if length == 0 then "is empty" elif .[0] != $begin then "does not start with \($begin)" elif .[-1] != $end then "does not end with \($end)" elif length < 3 then "has no key between its first and last line" else empty end | { address: $ARGS.named.address, message: "the key \(.)" } ''} --arg address "$address" "$1"/channels/"$address" done ''; in { imports = [ # The module only uses crane for its default package. (import (inputs.tincr + "/nix/module.nix") { crane = null; }) ]; config = lib.mkMerge [ { environment.systemPackages = [ config.services.tincr.package ]; services.tincr.package = pkgs.tincr; services.tincr.networks.retiolum = { nodeName = host.name; listenPort = net.tinc.port; ed25519PrivateKeyFile = if config.enstate.enable then keySlot.path else "${config.krebs.secret.directory}/retiolum.ed25519_key.priv"; hosts = lib.mapAttrs (_: host: host.nets.retiolum.tinc.config) (lib.filterAttrs (_: host: host.nets ? retiolum && host.nets.retiolum.tinc.config or null != null) config.krebs.hosts); connectTo = builtins.filter (mylib.ne host.name) [ "ne" "neoprism" "eve" ]; interfaceName = "retiolum"; addresses = [ "${net.ip4.addr}/${toString net.ip4.prefixLength}" "${net.ip6.addr}/${toString net.ip6.prefixLength}" ]; extraConfig = '' Broadcast = no StrictSubnets = yes ''; }; systemd.services.tincr-retiolum.restartIfCredentialsChange = true; # tincd doesn't set the MTU. This is what kartei's retiolum module uses, # measured across the mesh, so paths that lose large packets don't # stall TCP. systemd.network.networks."40-tincr-retiolum".linkConfig.MTUBytes = "1377"; } (lib.mkIf config.enstate.enable { enstate.types.${keyType}.validator = keyValidator; enstate.channels.secrets.slots."retiolum.key" = { type = keyType; secret = true; source = lib.mkDefault { command = [ "secrets" host.name "retiolum.ed25519_key.priv" ]; }; }; }) (lib.mkIf (!config.hrm.nftables.enable) { tv.iptables.input-internet-accept-tcp = [ "tinc" ]; tv.iptables.input-internet-accept-udp = [ "tinc" ]; }) (lib.mkIf config.hrm.nftables.enable { hrm.nftables.input.internet.tcp = [ "tinc" ]; hrm.nftables.input.internet.udp = [ "tinc" ]; }) ]; }