This repository has no description
3.9 kB
118 lines
1{
2 self,
3 config,
4 pkgs,
5 lib,
6 ...
7}:
8
9let
10 tincr = self.packages.${pkgs.system}.tincr;
11 tincrPkg = pkgs.runCommand "tincr-sbin-${tincr.version}" { version = tincr.version; } ''
12 mkdir -p $out
13 cp -r ${tincr}/* $out/
14 chmod -R u+w $out
15 ln -s bin $out/sbin
16 '';
17
18 # Peer keys and addresses come straight from kartei, not through
19 # stockholm's krebs.hosts: stockholm pins an older kartei and its host type
20 # still requires the legacy RSA pubkey. This is only the host database --
21 # the daemon stays on nixpkgs' services.tinc (kartei's own retiolum module
22 # is nix-darwin only here, see machines/barnacle/retiolum.nix).
23 #
24 # tincHosts is already filtered to SPTPS-capable nodes, so the RSA-only
25 # leftovers tincr refuses per connection attempt are gone.
26 kartei = import (self.inputs.kartei + "/modules/retiolum/hosts.nix") { inherit lib; };
27
28 name = config.networking.hostName;
29
30 # Nodes with no kartei card, known only inside superconfig. Exposes the same
31 # interface as kartei's hosts.nix, so both sources merge the same way.
32 local = self.retiolum;
33
34 own = kartei.own.${name} or local.own.${name};
35in
36
37{
38
39 networking.firewall.allowedTCPPorts = [ 655 ];
40 networking.firewall.allowedUDPPorts = [ 655 ];
41
42 services.tinc.networks.retiolum = {
43 package = tincrPkg;
44 # 1+ maps to per-packet Debug/Trace in tincr, which floods journald
45 # (tens of thousands of suppressed messages per minute) and rotates
46 # all other units' logs out of the journal within hours
47 debugLevel = 0;
48 hosts = kartei.tincHosts // local.tincHosts;
49 extraConfig = ''
50 AutoConnect = yes
51 LocalDiscovery = yes
52 '';
53 settings = {
54 Interface = "retiolum";
55 Name = name;
56 ConnectTo = [
57 "neoprism"
58 "ni"
59 "eve"
60 ];
61 };
62 };
63
64 # Copy keys into the tinc config directory before tinc starts.
65 # Running before nixpkgs' preStart ensures key generation is skipped.
66 systemd.services."tinc.retiolum".preStart = lib.mkBefore ''
67 rm -f /etc/tinc/retiolum/rsa_key.priv /etc/tinc/retiolum/ed25519_key.priv /etc/tinc/retiolum/tinc-up
68 cp ${
69 config.clan.core.vars.generators.retiolum.files."retiolum.rsa_key.priv".path
70 } /etc/tinc/retiolum/rsa_key.priv
71 cp ${
72 config.clan.core.vars.generators.retiolum.files."retiolum.ed25519_key.priv".path
73 } /etc/tinc/retiolum/ed25519_key.priv
74 chown tinc-retiolum /etc/tinc/retiolum/rsa_key.priv /etc/tinc/retiolum/ed25519_key.priv
75 chmod 600 /etc/tinc/retiolum/rsa_key.priv /etc/tinc/retiolum/ed25519_key.priv
76 '';
77
78 clan.core.vars.generators.retiolum = {
79 files."retiolum.rsa_key.priv" = { };
80 files."retiolum.ed25519_key.priv" = { };
81 files."retiolum.rsa_key.pub".secret = false;
82 files."retiolum.ed25519_key.pub".secret = false;
83 runtimeInputs = with pkgs; [
84 coreutils
85 tinc_pre
86 ];
87 script = ''
88 tinc --config "$out" generate-keys 4096 >/dev/null
89 mv "$out"/rsa_key.priv "$out"/retiolum.rsa_key.priv
90 mv "$out"/ed25519_key.priv "$out"/retiolum.ed25519_key.priv
91 mv "$out"/rsa_key.pub "$out"/retiolum.rsa_key.pub
92 mv "$out"/ed25519_key.pub "$out"/retiolum.ed25519_key.pub
93 '';
94 };
95
96 systemd.network.networks.retiolum = {
97 matchConfig.Name = "retiolum";
98 address = lib.optional (own.ip4 != null) "${own.ip4}/16" ++ [ "${own.ip6}/16" ];
99 linkConfig = {
100 MTUBytes = "1377";
101 RequiredForOnline = "no";
102 };
103 networkConfig = {
104 LinkLocalAddressing = "no";
105 };
106 };
107
108 environment.systemPackages = [
109 tincrPkg
110 ];
111
112 # Upstream nixos/tinc preStart chowns hosts/ and invitations/ but not
113 # the network dir itself, so tincr (and tinc 1.1pre18) can't persist
114 # its address-cache there. Drop this once nixpkgs#520533 lands.
115 systemd.tmpfiles.rules = [
116 "z /etc/tinc/retiolum 0755 tinc-retiolum - -"
117 ];
118}