nixos/hound: adopt, rework, cleanup (#268983)

- add me as maintainer
- remove hardcoded user id
- validate syntax of config file
- remove superfluous option extraGroups
- use mkPackageOptionMD
This commit is contained in:
Sandro 2023-12-05 15:59:26 +01:00 committed by GitHub
parent f918ac9dcd
commit d011c93f7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 43 deletions

View File

@ -288,7 +288,7 @@ in
telegraf = 256;
gitlab-runner = 257;
postgrey = 258;
hound = 259;
# hound = 259; # unused, removed 2023-11-21
leaps = 260;
ipfs = 261;
# stanchion = 262; # unused, removed 2020-10-14
@ -599,7 +599,7 @@ in
#telegraf = 256; # unused
gitlab-runner = 257;
postgrey = 258;
hound = 259;
# hound = 259; # unused, removed 2023-11-21
leaps = 260;
ipfs = 261;
# stanchion = 262; # unused, removed 2020-10-14

View File

@ -3,6 +3,12 @@ with lib;
let
cfg = config.services.hound;
in {
imports = [
(lib.mkRemovedOptionModule [ "services" "hound" "extraGroups" ] "Use users.users.hound.extraGroups instead")
];
meta.maintainers = with maintainers; [ SuperSandro2000 ];
options = {
services.hound = {
enable = mkOption {
@ -13,6 +19,8 @@ in {
'';
};
package = mkPackageOptionMD pkgs "hound" { };
user = mkOption {
default = "hound";
type = types.str;
@ -29,27 +37,15 @@ in {
'';
};
extraGroups = mkOption {
type = types.listOf types.str;
default = [ ];
example = [ "dialout" ];
description = lib.mdDoc ''
List of extra groups that the "hound" user should be a part of.
'';
};
home = mkOption {
default = "/var/lib/hound";
type = types.path;
description = lib.mdDoc ''
The path to use as hound's $HOME. If the default user
"hound" is configured then this is the home of the "hound"
user.
The path to use as hound's $HOME.
If the default user "hound" is configured then this is the home of the "hound" user.
'';
};
package = mkPackageOption pkgs "hound" { };
config = mkOption {
type = types.str;
description = lib.mdDoc ''
@ -57,63 +53,62 @@ in {
should be an absolute path to a writable location on disk.
'';
example = literalExpression ''
'''
{
"max-concurrent-indexers" : 2,
"dbpath" : "''${services.hound.home}/data",
"repos" : {
"nixpkgs": {
"url" : "https://www.github.com/NixOS/nixpkgs.git"
}
}
{
"max-concurrent-indexers" : 2,
"repos" : {
"nixpkgs": {
"url" : "https://www.github.com/NixOS/nixpkgs.git"
}
}
'''
}
'';
};
listen = mkOption {
type = types.str;
default = "0.0.0.0:6080";
example = "127.0.0.1:6080 or just :6080";
example = ":6080";
description = lib.mdDoc ''
Listen on this IP:port / :port
Listen on this [IP]:port
'';
};
};
};
config = mkIf cfg.enable {
users.groups = optionalAttrs (cfg.group == "hound") {
hound.gid = config.ids.gids.hound;
users.groups = lib.mkIf (cfg.group == "hound") {
hound = { };
};
users.users = optionalAttrs (cfg.user == "hound") {
users.users = lib.mkIf (cfg.user == "hound") {
hound = {
description = "hound code search";
description = "Hound code search";
createHome = true;
home = cfg.home;
group = cfg.group;
extraGroups = cfg.extraGroups;
uid = config.ids.uids.hound;
isSystemUser = true;
inherit (cfg) home group;
};
};
systemd.services.hound = {
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 {
description = "Hound Code Search";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
User = cfg.user;
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 ${pkgs.writeText "hound.json" cfg.config}";
ExecStart = "${cfg.package}/bin/houndd -addr ${cfg.listen} -conf ${configFile}";
};
};
};
}