Skip to content

Commit

Permalink
Merge pull request #322508 from MarcelCoding/hound
Browse files Browse the repository at this point in the history
hound: convert to use freeform type
  • Loading branch information
SuperSandro2000 authored Jun 28, 2024
2 parents 4e15c4a + ccd042b commit 0cbf178
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 43 deletions.
84 changes: 41 additions & 43 deletions nixos/modules/services/search/hound.nix
Original file line number Diff line number Diff line change
@@ -1,71 +1,66 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.hound;
settingsFormat = pkgs.formats.json { };
in {
imports = [
(lib.mkRemovedOptionModule [ "services" "hound" "extraGroups" ] "Use users.users.hound.extraGroups instead")
(lib.mkChangedOptionModule [ "services" "hound" "config" ] [ "services" "hound" "settings" ] (config: builtins.fromJSON config.services.hound.config))
];

meta.maintainers = with maintainers; [ SuperSandro2000 ];
meta.maintainers = with lib.maintainers; [ SuperSandro2000 ];

options = {
services.hound = {
enable = mkOption {
type = types.bool;
default = false;
description = ''
Whether to enable the hound code search daemon.
'';
};
enable = lib.mkEnableOption "hound";

package = mkPackageOption pkgs "hound" { };
package = lib.mkPackageOption pkgs "hound" { };

user = mkOption {
user = lib.mkOption {
default = "hound";
type = types.str;
type = lib.types.str;
description = ''
User the hound daemon should execute under.
'';
};

group = mkOption {
group = lib.mkOption {
default = "hound";
type = types.str;
type = lib.types.str;
description = ''
Group the hound daemon should execute under.
'';
};

home = mkOption {
home = lib.mkOption {
default = "/var/lib/hound";
type = types.path;
type = lib.types.path;
description = ''
The path to use as hound's $HOME.
If the default user "hound" is configured then this is the home of the "hound" user.
'';
};

config = mkOption {
type = types.str;
description = ''
The full configuration of the Hound daemon. Note the dbpath
should be an absolute path to a writable location on disk.
'';
example = literalExpression ''
settings = lib.mkOption {
type = settingsFormat.type;
example = lib.literalExpression ''
{
"max-concurrent-indexers" : 2,
"repos" : {
"nixpkgs": {
"url" : "https://www.github.com/NixOS/nixpkgs.git"
}
}
max-concurrent-indexers = 2;
repos.nixpkgs.url = "https://www.github.com/NixOS/nixpkgs.git";
}
'';
description = ''
The full configuration of the Hound daemon.
See the upstream documentation <https://github.com/hound-search/hound/blob/main/docs/config-options.md> for details.
:::{.note}
The `dbpath` should be an absolute path to a writable directory.
:::.com/hound-search/hound/blob/main/docs/config-options.md>.
'';
};

listen = mkOption {
type = types.str;
listen = lib.mkOption {
type = lib.types.str;
default = "0.0.0.0:6080";
example = ":6080";
description = ''
Expand All @@ -75,7 +70,7 @@ in {
};
};

config = mkIf cfg.enable {
config = lib.mkIf cfg.enable {
users.groups = lib.mkIf (cfg.group == "hound") {
hound = { };
};
Expand All @@ -89,16 +84,19 @@ in {
};
};

systemd.services.hound = let
configFile = pkgs.writeTextFile {
name = "hound.json";
text = cfg.config;
checkPhase = ''
# check if the supplied text is valid json
${lib.getExe pkgs.jq} . $target > /dev/null
'';
};
in {
environment.etc."hound/config.json".source = pkgs.writeTextFile {
name = "hound-config";
text = builtins.toJSON cfg.settings;
checkPhase = ''
${cfg.package}/bin/houndd -check-conf -conf $out
'';
};

services.hound.settings = {
dbpath = "${config.services.hound.home}/data";
};

systemd.services.hound = {
description = "Hound Code Search";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
Expand All @@ -107,7 +105,7 @@ in {
Group = cfg.group;
WorkingDirectory = cfg.home;
ExecStartPre = "${pkgs.git}/bin/git config --global --replace-all http.sslCAinfo /etc/ssl/certs/ca-certificates.crt";
ExecStart = "${cfg.package}/bin/houndd -addr ${cfg.listen} -conf ${configFile}";
ExecStart = "${cfg.package}/bin/houndd -addr ${cfg.listen} -conf /etc/hound/config.json";
};
};
};
Expand Down
14 changes: 14 additions & 0 deletions pkgs/development/tools/misc/hound/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
, git
, openssh
, nixosTests
, fetchpatch
}:

buildGoModule rec {
Expand All @@ -19,6 +20,19 @@ buildGoModule rec {
sha256 = "sha256-Qdk57zLjTXLdDEmB6K+sZAym5s0BekJJa/CpYeOBOcY=";
};

patches = [
# add check config flag
# https://github.com/hound-search/hound/pull/485/files
(fetchpatch {
url = "https://github.com/MarcelCoding/hound/commit/b2f1cef335eff235394de336593687236a3b88bb.patch";
hash = "sha256-3+EBvnA8JIx2P6YM+8LpojDIX7hNXJ0vwVN4oSAouZ4=";
})
(fetchpatch {
url = "https://github.com/MarcelCoding/hound/commit/f917a457570ad8659d02fca4311cc91cadcadc00.patch";
hash = "sha256-CGvcIoSbgiayli5B8JRjvGfLuH2fscNpNTEm7xwkfpo=";
})
];

vendorHash = "sha256-0psvz4bnhGuwwSAXvQp0ju0GebxoUyY2Rjp/D43KF78=";

nativeBuildInputs = [ makeWrapper ];
Expand Down

0 comments on commit 0cbf178

Please sign in to comment.