summaryrefslogtreecommitdiff
path: root/modules/yggdrasil/default.nix
blob: 91a550d6d1f4527d8cb42c6868e9367a71f70f5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
{ config, lib, customUtils, ... }:
let
  cfg = config.services.tinc.yggdrasil;
in {
  options = {
    services.tinc.yggdrasil = lib.mkOption {
      type = lib.types.submodule {
        options = {
          enable = lib.mkEnableOption "Yggdrasil tinc network";
          
          connect = lib.mkOption {
            default = true;
            type = lib.types.bool;
            description = ''
              Connect to central server
            '';
          };
        };
      };
    };
  };
  
  config = lib.mkIf cfg.enable {
    services.tinc.networks.yggdrasil = {
      name = config.networking.hostName;
      hostSettings = customUtils.recImport { dir = ./hosts; };
      debugLevel = 2;
      interfaceType = "tap";
      settings = {
        Mode = "switch";
        PingTimeout = 30;
        ConnectTo = lib.mkIf cfg.connect "ymir";
      };
    };

    sops.secrets = {
      tinc-yggdrasil-rsa = {
        key = "rsa";
        path = "/etc/tinc/yggdrasil/rsa_key.priv";
        sopsFile = ./hosts + "/${config.services.tinc.networks.yggdrasil.name}/private-keys.yaml";
      };
      tinc-yggdrasil-ed25519 = {
        key = "ed25519";
        path = "/etc/tinc/yggdrasil/rsa_key.priv";
        sopsFile = ./hosts + "/${config.services.tinc.networks.yggdrasil.name}/private-keys.yaml";
      };
    };
  };
}