about summary refs log tree commit diff
path: root/users/wpcarro/nixos/diogenes/default.nix
blob: e83329e4c2664e6d05589fe8f9d9b4387e29e057 (plain) (blame)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
{ depot, pkgs, ... }:

let
  inherit (depot.users) wpcarro;
  name = "diogenes";
  domainName = "billandhiscomputer.com";

  mod = name: depot.path.origSrc + ("/ops/modules/" + name);
  usermod = name: depot.path.origSrc + ("/users/wpcarro/nixos/modules/" + name);
in
wpcarro.terraform.googleCloudVM {
  project = "wpcarros-infrastructure";
  name = "diogenes";
  region = "us-central1";
  zone = "us-central1-a";

  # DNS configuration
  extraConfig = {
    # billandhiscomputer.com
    resource.google_dns_managed_zone."${name}" = {
      inherit name;
      dns_name = "${domainName}.";
    };

    resource.google_dns_record_set."${name}" = {
      name = "${domainName}.";
      type = "A";
      ttl = 300; # 5m
      managed_zone = "\${google_dns_managed_zone.${name}.name}";
      rrdatas = [ "\${google_compute_instance.${name}.network_interface[0].access_config[0].nat_ip}" ];
    };

    resource.google_compute_instance."${name}" = {
      network_interface.access_config = {
        public_ptr_domain_name = "${domainName}.";
      };
    };
  };

  configuration = {
    imports = [
      (mod "quassel.nix")
      (usermod "nginx.nix")
      (usermod "www/billandhiscomputer.com.nix")
      (usermod "www/wpcarro.dev.nix")
    ];

    networking = {
      firewall.allowedTCPPorts = [
        22 # ssh
        80 # http
        443 # https
        6698 # quassel
      ];
      firewall.allowedUDPPortRanges = [
        { from = 60000; to = 61000; } # mosh
      ];
    };

    # Use the TVL binary cache
    tvl.cache.enable = true;

    users = {
      mutableUsers = true;
      users = {
        root = {
          openssh.authorizedKeys.keys = wpcarro.keys.all;
        };
        wpcarro = {
          isNormalUser = true;
          extraGroups = [ "wheel" "quassel" ];
          openssh.authorizedKeys.keys = wpcarro.keys.all;
          shell = pkgs.fish;
        };
        # This is required so that quasselcore can read the ACME cert in
        # /var/lib/acme, which is only available to user=acme or group=nginx.
        quassel.extraGroups = [ "nginx" ];
      };
    };

    security = {
      acme = {
        acceptTerms = true;
        defaults.email = "wpcarro@gmail.com";
      };

      sudo.wheelNeedsPassword = false;
    };

    programs = wpcarro.common.programs // {
      mosh.enable = true;
    };

    # I won't have an Emacs server running on diogenes, and I'll likely be in an
    # SSH session from within vterm. As such, Vim is one of the few editors that
    # I tolerably navigate this way.
    environment.variables = {
      EDITOR = "vim";
    };

    environment.systemPackages = wpcarro.common.shell-utils;

    services = wpcarro.common.services // {
      # TODO(wpcarro): Re-enable this when rebuild-system better supports
      # terraform deployments.
      # depot.auto-deploy = {
      #   enable = true;
      #   interval = "1h";
      # };

      # TODO(wpcarro): Re-enable this after debugging ACME and NXDOMAIN.
      depot.quassel = {
        enable = true;
        acmeHost = domainName;
        bindAddresses = [
          "0.0.0.0"
        ];
      };

      journaldriver = {
        enable = true;
        logStream = "home";
        googleCloudProject = "wpcarros-infrastructure";
        applicationCredentials = "/etc/gcp/key.json";
      };
    };

    system.stateVersion = "21.11";
  };
}