aboutsummaryrefslogtreecommitdiff
path: root/home-manager/modules/services/hound.nix
blob: a252a68d271ff5e860cefc199b94d4cfe904868d (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
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
{ config, lib, pkgs, ... }:

with lib;

let

  cfg = config.services.hound;

  configFile = pkgs.writeText "hound-config.json" (
    builtins.toJSON {
      max-concurrent-indexers = cfg.maxConcurrentIndexers;
      dbpath = cfg.databasePath;
      repos = cfg.repositories;
      health-check-url = "/healthz";
    }
  );

  houndOptions = [
    "--addr ${cfg.listenAddress}"
    "--conf ${configFile}"
  ];

in

{
  meta.maintainers = [ maintainers.adisbladis ];

  options.services.hound = {
    enable = mkEnableOption "hound";

    maxConcurrentIndexers = mkOption {
      type = types.ints.positive;
      default = 2;
      description = "Limit the amount of concurrent indexers.";
    };

    databasePath = mkOption {
      type = types.path;
      default = "${config.xdg.dataHome}/hound";
      defaultText = "\$XDG_DATA_HOME/hound";
      description = "The Hound database path.";
    };

    listenAddress = mkOption {
      type = types.str;
      default = "localhost:6080";
      description = "Listen address of the Hound daemon.";
    };

    repositories = mkOption {
      type = types.attrsOf (types.uniq types.attrs);
      default = {};
      example = literalExample ''
        {
          SomeGitRepo = {
            url = "https://www.github.com/YourOrganization/RepoOne.git";
            ms-between-poll = 10000;
            exclude-dot-files = true;
          };
        }
      '';
      description = "The repository configuration.";
    };
  };

  config = mkIf cfg.enable {
    home.packages = [ pkgs.hound ];

    systemd.user.services.hound = {
      Unit = {
        Description = "Hound source code search engine";
      };

      Install = {
        WantedBy = [ "default.target" ];
      };

      Service = {
        Environment = "PATH=${makeBinPath [ pkgs.mercurial pkgs.git ]}";
        ExecStart = "${pkgs.hound}/bin/houndd ${concatStringsSep " " houndOptions}";
      };
    };
  };
}