1{ config, lib, pkgs, ... }:
2with lib;
3let
4 cfg = config.services.hound;
5in {
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 defaultText = "pkgs.hound";
54 type = types.package;
55 description = ''
56 Package for running hound.
57 '';
58 };
59
60 config = mkOption {
61 type = types.str;
62 description = ''
63 The full configuration of the Hound daemon. Note the dbpath
64 should be an absolute path to a writable location on disk.
65 '';
66 example = ''
67 {
68 "max-concurrent-indexers" : 2,
69 "dbpath" : "''${services.hound.home}/data",
70 "repos" : {
71 "nixpkgs": {
72 "url" : "https://www.github.com/NixOS/nixpkgs.git"
73 }
74 }
75 }
76 '';
77 };
78
79 listen = mkOption {
80 type = types.str;
81 default = "0.0.0.0:6080";
82 example = "127.0.0.1:6080 or just :6080";
83 description = ''
84 Listen on this IP:port / :port
85 '';
86 };
87 };
88 };
89
90 config = mkIf cfg.enable {
91 users.groups = optional (cfg.group == "hound") {
92 name = "hound";
93 gid = config.ids.gids.hound;
94 };
95
96 users.users = optional (cfg.user == "hound") {
97 name = "hound";
98 description = "hound code search";
99 createHome = true;
100 home = cfg.home;
101 group = cfg.group;
102 extraGroups = cfg.extraGroups;
103 uid = config.ids.uids.hound;
104 };
105
106 systemd.services.hound = {
107 description = "Hound Code Search";
108 wantedBy = [ "multi-user.target" ];
109 after = [ "network.target" ];
110
111 serviceConfig = {
112 User = cfg.user;
113 Group = cfg.group;
114 WorkingDirectory = cfg.home;
115 ExecStartPre = "${pkgs.git}/bin/git config --global --replace-all http.sslCAinfo /etc/ssl/certs/ca-certificates.crt";
116 ExecStart = "${cfg.package}/bin/houndd" +
117 " -addr ${cfg.listen}" +
118 " -conf ${pkgs.writeText "hound.json" cfg.config}";
119
120 };
121 path = [ pkgs.git pkgs.mercurial pkgs.openssh ];
122 };
123 };
124
125}