@@ -0,0 +1,119 @@
1+{ config, lib, pkgs, ... }:
2+with lib;
3+let
4+ cfg = config.services.hound;
5+in {
6+ options = {
7+ services.hound = {
8+ enable = mkOption {
9+ type = types.bool;
10+ default = false;
11+ description = ''
12+ Whether to enable the hound code search daemon.
13+ '';
14+ };
15+
16+ user = mkOption {
17+ default = "hound";
18+ type = types.str;
19+ description = ''
20+ User the hound daemon should execute under.
21+ '';
22+ };
23+
24+ group = mkOption {
25+ default = "hound";
26+ type = types.str;
27+ description = ''
28+ Group the hound daemon should execute under.
29+ '';
30+ };
31+
32+ extraGroups = mkOption {
33+ type = types.listOf types.str;
34+ default = [ ];
35+ example = [ "dialout" ];
36+ description = ''
37+ List of extra groups that the "hound" user should be a part of.
38+ '';
39+ };
40+
41+ home = mkOption {
42+ default = "/var/lib/hound";
43+ type = types.path;
44+ description = ''
45+ The path to use as hound's $HOME. If the default user
46+ "hound" is configured then this is the home of the "hound"
47+ user.
48+ '';
49+ };
50+
51+ package = mkOption {
52+ default = pkgs.hound;
53+ description = ''
54+ Package for running hound.
55+ '';
56+ };
57+
58+ config = mkOption {
59+ type = types.str;
60+ example = ''
61+ {
62+ "max-concurrent-indexers" : 2,
63+ "dbpath" : "''${services.hound.home}/data",
64+ "repos" : {
65+ "nixpkgs": {
66+ "url" : "https://www.github.com/NixOS/nixpkgs.git"
67+ }
68+ }
69+ }
70+ '';
71+ };
72+
73+ listen = mkOption {
74+ type = types.str;
75+ default = "0.0.0.0:6080";
76+ example = "127.0.0.1:6080 or just :6080";
77+ description = ''
78+ Listen on this IP:port / :port
79+ '';
80+ };
81+ };
82+ };
83+
84+ config = mkIf cfg.enable {
85+ users.extraGroups = optional (cfg.group == "hound") {
86+ name = "hound";
87+ gid = config.ids.gids.hound;
88+ };
89+
90+ users.extraUsers = optional (cfg.user == "hound") {
91+ name = "hound";
92+ description = "hound code search";
93+ createHome = true;
94+ home = cfg.home;
95+ group = cfg.group;
96+ extraGroups = cfg.extraGroups;
97+ uid = config.ids.uids.hound;
98+ };
99+
100+ systemd.services.hound = {
101+ description = "Hound Code Search";
102+ wantedBy = [ "multi-user.target" ];
103+ after = [ "network.target" ];
104+
105+ serviceConfig = {
106+ User = cfg.user;
107+ Group = cfg.group;
108+ WorkingDirectory = cfg.home;
109+ ExecStartPre = "${pkgs.git}/bin/git config --global --replace-all http.sslCAinfo /etc/ssl/certs/ca-certificates.crt";
110+ ExecStart = "${cfg.package}/bin/houndd" +
111+ " -addr ${cfg.listen}" +
112+ " -conf ${pkgs.writeText "hound.json" cfg.config}";
113+
114+ };
115+ path = [ pkgs.git ];
116+ };
117+ };
118+
119+}