retiolum/modules/retiolum/default.nix

93 lines
2.3 KiB
Nix
Raw Normal View History

2020-08-02 21:06:41 +00:00
{ config, pkgs, lib, ... }:
with lib;
let
netname = "retiolum";
cfg = config.networking.retiolum;
in {
options = {
networking.retiolum.ipv4 = mkOption {
type = types.str;
description = ''
own ipv4 address
'';
};
networking.retiolum.ipv6 = mkOption {
type = types.str;
description = ''
own ipv6 address
'';
};
networking.retiolum.nodename = mkOption {
type = types.str;
default = config.networking.hostName;
description = ''
tinc network name
'';
};
};
config = {
services.tinc.networks.${netname} = {
name = cfg.nodename;
extraConfig = ''
LocalDiscovery = yes
ConnectTo = gum
ConnectTo = ni
ConnectTo = prism
ConnectTo = eve
2020-11-27 12:45:16 +00:00
ConnectTo = eva
2020-08-02 21:06:41 +00:00
AutoConnect = yes
'';
};
networking.extraHosts = builtins.readFile ../../etc.hosts;
2020-11-01 08:30:04 +00:00
environment.systemPackages = [
config.services.tinc.networks.${netname}.package
];
2020-08-02 21:06:41 +00:00
2020-11-01 08:30:04 +00:00
systemd.services."tinc.${netname}-host-keys" = {
description = "Install tinc.${netname} host keys";
2020-11-01 08:37:31 +00:00
requiredBy = [ "tinc.${netname}.service" ];
before = [ "tinc.${netname}.service" ];
2020-11-01 08:30:04 +00:00
script = ''
rm -rf /etc/tinc/${netname}/hosts
cp -R ${../../hosts} /etc/tinc/${netname}/hosts
chown -R tinc.${netname} /etc/tinc/${netname}/hosts
chmod -R u+w /etc/tinc/${netname}/hosts
'';
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
};
2020-11-01 08:30:04 +00:00
};
2020-12-12 06:45:02 +00:00
systemd.services."tinc.${netname}" = {
# Some hosts require VPN for nixos-rebuild, so we don't want to restart it on update
reloadIfChanged = true;
# also in https://github.com/NixOS/nixpkgs/pull/106715
serviceConfig.ExecReload = "${config.services.tinc.networks.${netname}.package}/bin/tinc -n ${netname} reload";
};
2020-08-02 21:06:41 +00:00
networking.firewall.allowedTCPPorts = [ 655 ];
networking.firewall.allowedUDPPorts = [ 655 ];
systemd.network.enable = true;
systemd.network.networks."${netname}".extraConfig = ''
[Match]
Name = tinc.${netname}
2020-08-16 15:53:33 +00:00
[Link]
2020-08-16 14:56:03 +00:00
# tested with `ping -6 turingmachine.r -s 1378`, not sure how low it must be
2020-08-16 15:53:33 +00:00
MTUBytes=1377
[Network]
2020-08-02 21:06:41 +00:00
Address=${cfg.ipv4}/12
Address=${cfg.ipv6}/16
'';
};
}