From 81b8f02ce40360319b88bc665445ee3c6c1b27fa Mon Sep 17 00:00:00 2001 From: Marcel Date: Mon, 24 Jun 2024 21:54:02 +0200 Subject: [PATCH 1/5] hound: cherry-pick conf check flag --- pkgs/development/tools/misc/hound/default.nix | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkgs/development/tools/misc/hound/default.nix b/pkgs/development/tools/misc/hound/default.nix index b906456116c5..6e3124556f54 100644 --- a/pkgs/development/tools/misc/hound/default.nix +++ b/pkgs/development/tools/misc/hound/default.nix @@ -6,6 +6,7 @@ , git , openssh , nixosTests +, fetchpatch }: buildGoModule rec { @@ -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 ]; From 73e7708bee0b468494480533445a2136a83bb121 Mon Sep 17 00:00:00 2001 From: Marcel Date: Tue, 25 Jun 2024 22:30:44 +0200 Subject: [PATCH 2/5] nixos/hound: cleanup services.hound.enable --- nixos/modules/services/search/hound.nix | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/nixos/modules/services/search/hound.nix b/nixos/modules/services/search/hound.nix index 059f514234eb..0a6abc61c134 100644 --- a/nixos/modules/services/search/hound.nix +++ b/nixos/modules/services/search/hound.nix @@ -11,13 +11,7 @@ in { options = { services.hound = { - enable = mkOption { - type = types.bool; - default = false; - description = '' - Whether to enable the hound code search daemon. - ''; - }; + enable = mkEnableOption "hound"; package = mkPackageOption pkgs "hound" { }; From e6979857a3f27142696fcd5b909cce741e9cedb5 Mon Sep 17 00:00:00 2001 From: Marcel Date: Mon, 24 Jun 2024 21:57:46 +0200 Subject: [PATCH 3/5] nixos/hound: convert config to free-form type, add config check --- nixos/modules/services/search/hound.nix | 47 +++++++++++++------------ 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/nixos/modules/services/search/hound.nix b/nixos/modules/services/search/hound.nix index 0a6abc61c134..054f8c71c84b 100644 --- a/nixos/modules/services/search/hound.nix +++ b/nixos/modules/services/search/hound.nix @@ -2,9 +2,11 @@ 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 ]; @@ -40,22 +42,22 @@ in { ''; }; - 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. - ''; + settings = mkOption { + type = settingsFormat.type; example = 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 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 { @@ -83,16 +85,15 @@ 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 + ''; + }; + + systemd.services.hound = { description = "Hound Code Search"; wantedBy = [ "multi-user.target" ]; after = [ "network.target" ]; @@ -101,7 +102,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"; }; }; }; From d7977717ac447716d8421adfa8c3a8f51b611dd1 Mon Sep 17 00:00:00 2001 From: Marcel Date: Wed, 26 Jun 2024 18:57:42 +0200 Subject: [PATCH 4/5] nixos/hound: remove `with lib;` --- nixos/modules/services/search/hound.nix | 29 ++++++++++++------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/nixos/modules/services/search/hound.nix b/nixos/modules/services/search/hound.nix index 054f8c71c84b..9715e478e53a 100644 --- a/nixos/modules/services/search/hound.nix +++ b/nixos/modules/services/search/hound.nix @@ -1,5 +1,4 @@ { config, lib, pkgs, ... }: -with lib; let cfg = config.services.hound; settingsFormat = pkgs.formats.json { }; @@ -9,42 +8,42 @@ in { (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 = mkEnableOption "hound"; + 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. ''; }; - settings = mkOption { + settings = lib.mkOption { type = settingsFormat.type; - example = literalExpression '' + example = lib.literalExpression '' { max-concurrent-indexers = 2; repos.nixpkgs.url = "https://www.github.com/NixOS/nixpkgs.git"; @@ -60,8 +59,8 @@ in { ''; }; - listen = mkOption { - type = types.str; + listen = lib.mkOption { + type = lib.types.str; default = "0.0.0.0:6080"; example = ":6080"; description = '' @@ -71,7 +70,7 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { users.groups = lib.mkIf (cfg.group == "hound") { hound = { }; }; From ccd042b9695d0afbe62a5f9f8bd484b0eb2556d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Wed, 26 Jun 2024 22:48:10 +0200 Subject: [PATCH 5/5] nixos/hound: set reasonable default for dbpath --- nixos/modules/services/search/hound.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nixos/modules/services/search/hound.nix b/nixos/modules/services/search/hound.nix index 9715e478e53a..7aca1adc19b0 100644 --- a/nixos/modules/services/search/hound.nix +++ b/nixos/modules/services/search/hound.nix @@ -92,6 +92,10 @@ in { ''; }; + services.hound.settings = { + dbpath = "${config.services.hound.home}/data"; + }; + systemd.services.hound = { description = "Hound Code Search"; wantedBy = [ "multi-user.target" ];