at 25.11-pre 3.4 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7let 8 cfg = config.services.hound; 9 settingsFormat = pkgs.formats.json { }; 10 houndConfigFile = pkgs.writeTextFile { 11 name = "hound-config.json"; 12 text = builtins.toJSON cfg.settings; 13 checkPhase = '' 14 ${cfg.package}/bin/houndd -check-conf -conf $out 15 ''; 16 }; 17in 18{ 19 imports = [ 20 (lib.mkRemovedOptionModule [ 21 "services" 22 "hound" 23 "extraGroups" 24 ] "Use users.users.hound.extraGroups instead") 25 (lib.mkChangedOptionModule [ "services" "hound" "config" ] [ "services" "hound" "settings" ] ( 26 config: builtins.fromJSON config.services.hound.config 27 )) 28 ]; 29 30 meta.maintainers = with lib.maintainers; [ SuperSandro2000 ]; 31 32 options = { 33 services.hound = { 34 enable = lib.mkEnableOption "hound"; 35 36 package = lib.mkPackageOption pkgs "hound" { }; 37 38 user = lib.mkOption { 39 default = "hound"; 40 type = lib.types.str; 41 description = '' 42 User the hound daemon should execute under. 43 ''; 44 }; 45 46 group = lib.mkOption { 47 default = "hound"; 48 type = lib.types.str; 49 description = '' 50 Group the hound daemon should execute under. 51 ''; 52 }; 53 54 home = lib.mkOption { 55 default = "/var/lib/hound"; 56 type = lib.types.path; 57 description = '' 58 The path to use as hound's $HOME. 59 If the default user "hound" is configured then this is the home of the "hound" user. 60 ''; 61 }; 62 63 settings = lib.mkOption { 64 type = settingsFormat.type; 65 example = lib.literalExpression '' 66 { 67 max-concurrent-indexers = 2; 68 repos.nixpkgs.url = "https://www.github.com/NixOS/nixpkgs.git"; 69 } 70 ''; 71 description = '' 72 The full configuration of the Hound daemon. 73 See the upstream documentation <https://github.com/hound-search/hound/blob/main/docs/config-options.md> for details. 74 75 :::{.note} 76 The `dbpath` should be an absolute path to a writable directory. 77 :::.com/hound-search/hound/blob/main/docs/config-options.md>. 78 ''; 79 }; 80 81 listen = lib.mkOption { 82 type = lib.types.str; 83 default = "0.0.0.0:6080"; 84 example = ":6080"; 85 description = '' 86 Listen on this [IP]:port 87 ''; 88 }; 89 }; 90 }; 91 92 config = lib.mkIf cfg.enable { 93 users.groups = lib.mkIf (cfg.group == "hound") { 94 hound = { }; 95 }; 96 97 users.users = lib.mkIf (cfg.user == "hound") { 98 hound = { 99 description = "Hound code search"; 100 createHome = true; 101 isSystemUser = true; 102 inherit (cfg) home group; 103 }; 104 }; 105 106 environment.etc."hound/config.json".source = houndConfigFile; 107 108 services.hound.settings = { 109 dbpath = "${config.services.hound.home}/data"; 110 }; 111 112 systemd.services.hound = { 113 description = "Hound Code Search"; 114 wantedBy = [ "multi-user.target" ]; 115 after = [ "network.target" ]; 116 restartTriggers = [ houndConfigFile ]; 117 serviceConfig = { 118 User = cfg.user; 119 Group = cfg.group; 120 WorkingDirectory = cfg.home; 121 ExecStartPre = "${pkgs.git}/bin/git config --global --replace-all http.sslCAinfo ${config.security.pki.caBundle}"; 122 ExecStart = "${cfg.package}/bin/houndd -addr ${cfg.listen} -conf /etc/hound/config.json"; 123 }; 124 }; 125 }; 126}