git.iko.soy/typeable/nixpkgs
on master help sign in
hound: init module
commit6c7a605714b8971f889887e68f44e0ec1461012a authorGraham Christensen <graham@grahamc.com> dateWed 12 Oct 2016, 18:58 (10 years ago) parent14384f0
5 files changed+181
nixos/modules/misc/ids.nix+2 nixos/modules/module-list.nix+1 nixos/modules/services/search/hound.nix+119 nixos/release.nix+1 nixos/tests/hound.nix+58
nixos/modules/misc/ids.nix+2
@@ -276,6 +276,7 @@
276276 telegraf = 256;
277277 gitlab-runner = 257;
278278 postgrey = 258;
279+ hound = 259;
279280
280281 # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!
281282
@@ -522,6 +523,7 @@
522523 #telegraf = 256; # unused
523524 gitlab-runner = 257;
524525 postgrey = 258;
526+ hound = 259;
525527
526528 # When adding a gid, make sure it doesn't match an existing
527529 # uid. Users and groups with the same name should have equal
nixos/modules/module-list.nix+1
@@ -455,6 +455,7 @@
455455 ./services/scheduling/fcron.nix
456456 ./services/scheduling/marathon.nix
457457 ./services/search/elasticsearch.nix
458+ ./services/search/hound.nix
458459 ./services/search/kibana.nix
459460 ./services/search/solr.nix
460461 ./services/security/clamav.nix
nixos/modules/services/search/hound.nixnew file+119
@@ -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+}
nixos/release.nix+1
@@ -245,6 +245,7 @@ in rec {
245245 tests.gnome3-gdm = callTest tests/gnome3-gdm.nix {};
246246 tests.grsecurity = callTest tests/grsecurity.nix {};
247247 tests.hibernate = callTest tests/hibernate.nix {};
248+ tests.hound = callTest tests/hound.nix {};
248249 tests.i3wm = callTest tests/i3wm.nix {};
249250 tests.installer = callSubTests tests/installer.nix {};
250251 tests.influxdb = callTest tests/influxdb.nix {};
nixos/tests/hound.nixnew file+58
@@ -0,0 +1,58 @@
1+# Test whether `houndd` indexes nixpkgs
2+import ./make-test.nix ({ pkgs, ... } : {
3+ name = "hound";
4+ meta = with pkgs.stdenv.lib.maintainers; {
5+ maintainers = [ grahamc ];
6+ };
7+ machine = { config, pkgs, ... }: {
8+ services.hound = {
9+ enable = true;
10+ config = ''
11+ {
12+ "max-concurrent-indexers": 1,
13+ "dbpath": "/var/lib/hound/data",
14+ "repos": {
15+ "nix": {
16+ "url": "file:///var/lib/hound/my-git"
17+ }
18+ }
19+ }
20+ '';
21+ };
22+
23+ systemd.services.houndseed = {
24+ description = "seed hound with a git repo";
25+ requiredBy = [ "hound.service" ];
26+ before = [ "hound.service" ];
27+
28+ serviceConfig = {
29+ User = "hound";
30+ Group = "hound";
31+ WorkingDirectory = "/var/lib/hound";
32+ };
33+ path = [ pkgs.git ];
34+ script = ''
35+ git config --global user.email "you@example.com"
36+ git config --global user.name "Your Name"
37+ git init my-git --bare
38+ git init my-git-clone
39+ cd my-git-clone
40+ echo 'hi nix!' > hello
41+ git add hello
42+ git commit -m "hello there :)"
43+ git remote add origin /var/lib/hound/my-git
44+ git push origin master
45+ '';
46+ };
47+ };
48+
49+ testScript =
50+ '' startAll;
51+
52+ $machine->waitForUnit("network.target");
53+ $machine->waitForUnit("hound.service");
54+ $machine->waitForOpenPort(6080);
55+ $machine->succeed('curl http://127.0.0.1:6080/api/v1/search\?stats\=fosho\&repos\=\*\&rng=%3A20\&q\=hi\&files\=\&i=nope | grep "Filename" | grep "hello"');
56+
57+ '';
58+})