summary refs log tree commit diff
path: root/fleet/hosts/trieste/naut.nix
blob: 5b219acae976d85c79f05f18048588b41431b3de (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
# SPDX-FileCopyrightText: V <v@unfathomable.blue>
# SPDX-License-Identifier: OSL-3.0

{ pkgs, ... }:

let
  socket = "/run/naut/naut.sock";
  proxySocket = "/run/naut-proxy/naut.sock";
in {
  systemd.sockets.naut-proxy = {
    wantedBy = [ "sockets.target" ];
    listenStreams = [ proxySocket ];
    socketConfig.SocketUser = "git";
  };

  systemd.services.naut-proxy = {
    requires = [ "naut-proxy.socket" ];
    serviceConfig.ExecStart = "${pkgs.systemd}/lib/systemd/systemd-socket-proxyd ${socket}";
  };

  systemd.services.naut = {
    wantedBy = [ "multi-user.target" ];

    environment.NAUT_SOCK = socket;

    serviceConfig = {
      ExecStart = "${pkgs.naut}/bin/naut";
      EnvironmentFile = "/etc/naut/env";
      Restart = "on-failure";

      DynamicUser = true;
      SupplementaryGroups = [ "git" ];
      RuntimeDirectory = "naut";
    };
  };

  declarative.git.hooks.post-receive = [
    (pkgs.writeShellScript "nautify" ''
      {
        cat
      } | nc -UN ${proxySocket}
    '')
  ];
}