summaryrefslogtreecommitdiff
path: root/modules/hosts.nix
blob: 79ac3e6b55c32d7da4bc2406683d9a0d0150720a (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
{ lib, config, ... }:

let cfg = config.this.hosts;
in
{
  options = {
    this.hosts.lan.home = lib.mkEnableOption "Home LAN /etc/hosts";
    this.hosts.mine = lib.mkEnableOption "my /etc/hosts";
    this.hosts.alef.zoar.cx = lib.mkEnableOption "alef.zoar.cx /etc/hosts";
    this.hosts.yggdrasil.public = lib.mkOption {
      description = "Use Yggdrasil addresses for public hosts when possible.";
      type = lib.types.bool;
      default = false;
    };
    this.hosts.yggdrasil.private = lib.mkOption {
      description = "Use Yggdrasil addresses for non-public hosts when possible.";
      type = lib.types.bool;
      default = false;
    };
  };

  config = {
    networking.hosts =
      lib.optionalAttrs cfg.lan.home {
        "172.19.0.14" = ["sage.alef.zoar.cx" "sage"];
        "192.168.1.5" = ["rosemary.alef.zoar.cx" "rosemary"];
      } //
      lib.optionalAttrs cfg.mine {
        "${(if cfg.yggdrasil.public
            then "201:c37f:8bd1:de2c:531e:a3c8:6c38:aa3e"
            else "45.61.184.234")}" = ["alfheim"];
      } //
      lib.optionalAttrs cfg.alef.zoar.cx {
        "173.16.167.196" = ["sage.alef.zoar.cx" "sage"];
      };

    services.yggdrasil = lib.mkMerge [
      { persistentKeys = true; }
      (lib.mkIf cfg.yggdrasil.public or cfg.yggdrasil.private
        { enable = lib.mkDefault true; })
    ];
  };
}