2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
|
|
|
cfg = config.services.dictd;
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.dictd = {
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
enable = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Whether to enable the DICT.org dictionary server.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
DBs = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.package;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = with pkgs.dictdDBs; [ wiktionary wordnet ];
|
2024-09-19 14:19:46 +00:00
|
|
|
defaultText = lib.literalExpression "with pkgs.dictdDBs; [ wiktionary wordnet ]";
|
|
|
|
example = lib.literalExpression "[ pkgs.dictdDBs.nld2eng ]";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "List of databases to make available.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = let dictdb = pkgs.dictDBCollector { dictlist = map (x: {
|
|
|
|
name = x.name;
|
|
|
|
filename = x; } ) cfg.DBs; };
|
2024-09-19 14:19:46 +00:00
|
|
|
in lib.mkIf cfg.enable {
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
# get the command line client on system path to make some use of the service
|
|
|
|
environment.systemPackages = [ pkgs.dict ];
|
|
|
|
|
2022-07-14 12:49:19 +00:00
|
|
|
environment.etc."dict.conf".text = ''
|
|
|
|
server localhost
|
|
|
|
'';
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
users.users.dictd =
|
|
|
|
{ group = "dictd";
|
|
|
|
description = "DICT.org dictd server";
|
|
|
|
home = "${dictdb}/share/dictd";
|
|
|
|
uid = config.ids.uids.dictd;
|
|
|
|
};
|
|
|
|
|
|
|
|
users.groups.dictd.gid = config.ids.gids.dictd;
|
|
|
|
|
|
|
|
systemd.services.dictd = {
|
|
|
|
description = "DICT.org Dictionary Server";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
environment = { LOCALE_ARCHIVE = "/run/current-system/sw/lib/locale/locale-archive"; };
|
2024-07-27 06:49:29 +00:00
|
|
|
# Work around the fact that dictd doesn't handle SIGTERM; it terminates
|
|
|
|
# with code 143 instead of exiting with code 0.
|
|
|
|
serviceConfig.SuccessExitStatus = [ 143 ];
|
2020-04-24 23:36:52 +00:00
|
|
|
serviceConfig.Type = "forking";
|
|
|
|
script = "${pkgs.dict}/sbin/dictd -s -c ${dictdb}/share/dictd/dictd.conf --locale en_US.UTF-8";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|