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

{ pkgs, ... }:

let
  socket = "/run/naut/naut.sock";
  proxySocket = "/run/naut/naut-proxy.sock";

  config = {
      "#unfathomable" = [ "nixos-config" ];
      "#ripple" = [ "ripple" "ripple-website" ];
    };
in {
  systemd.sockets.naut-proxy = {
    wantedBy = [ "sockets.target" ];
    listenStreams = [ proxySocket ];
    socketConfig.SocketUser = "git";
  };

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

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

    environment.NAUT_SOCK = socket;
    environment.NAUT_CONFIG = (pkgs.formats.toml {}).generate "naut.toml" config;

    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" ''
      {
        pwd
        cat
      } | nc -UN ${proxySocket}
    '')
  ];
}