about summary refs log tree commit diff
path: root/nix/tazserve.nix
blob: 97e6313587e94aeffd7c8abb5688e4a90bda077a (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
{ pkgs, config, ... }:

with pkgs; let blogSource = fetchgit {
  url = "https://git.tazj.in/tazjin/tazblog.git";
  sha256 = "0m745vb8k6slzdsld63rbfg583k70q3g6i5lz576sccalkg0r2l2";
  rev = "aeeb11f1b76729115c4db98f419cbcda1a0f7660";
};
tazblog = import ./tazblog { inherit blogSource; };
blog = tazblog.tazblog;
blogConfig = {
  enableACME = true;
  forceSSL = true;
  locations."/" = {
    proxyPass = "http://127.0.0.1:8000";
  };
};
in {
  # Ensure that blog software is installed
  environment.systemPackages = [
    blog
    blogSource
  ];

  # Set up database unit
  systemd.services.tazblog-db =  {
    description           = "Database engine for Tazblog";
    script                = "${blog}/bin/tazblog-db";
    serviceConfig.restart = "always";
    wantedBy              = [ "multi-user.target" ];
  };

  # Set up blog unit
  systemd.services.tazblog = {
    description           = "Tazjin's blog engine";
    script                = "${blog}/bin/tazblog --resourceDir ${blogSource}/static";
    serviceConfig.restart = "always";
    requires              = [ "tazblog-db.service" ];
    wantedBy              = [ "multi-user.target" ];
  };

  # Set up Gogs
  services.gogs = {
    enable       = true;
    appName      = "Gogs: tazjin's private code";
    cookieSecure = true;
    domain       = "git.tazj.in";
    rootUrl      = "https://git.tazj.in/";
  };

  # Set up reverse proxy
  services.nginx = {
    enable = true;
    recommendedTlsSettings = true;
    recommendedProxySettings = true;

    # Blog!
    virtualHosts."tazj.in" = blogConfig;
    virtualHosts."www.tazj.in" = blogConfig;

    # Git!
    virtualHosts."git.tazj.in" = {
      enableACME = true;
      forceSSL   = true;
      locations."/" = {
        proxyPass = "http://127.0.0.1:3000";
      };
    };
  };
}