1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.dictd;
7in
8
9{
10
11 ###### interface
12
13 options = {
14
15 services.dictd = {
16
17 enable = mkOption {
18 type = types.bool;
19 default = false;
20 description = lib.mdDoc ''
21 Whether to enable the DICT.org dictionary server.
22 '';
23 };
24
25 DBs = mkOption {
26 type = types.listOf types.package;
27 default = with pkgs.dictdDBs; [ wiktionary wordnet ];
28 defaultText = literalExpression "with pkgs.dictdDBs; [ wiktionary wordnet ]";
29 example = literalExpression "[ pkgs.dictdDBs.nld2eng ]";
30 description = lib.mdDoc "List of databases to make available.";
31 };
32
33 };
34
35 };
36
37
38 ###### implementation
39
40 config = let dictdb = pkgs.dictDBCollector { dictlist = map (x: {
41 name = x.name;
42 filename = x; } ) cfg.DBs; };
43 in mkIf cfg.enable {
44
45 # get the command line client on system path to make some use of the service
46 environment.systemPackages = [ pkgs.dict ];
47
48 environment.etc."dict.conf".text = ''
49 server localhost
50 '';
51
52 users.users.dictd =
53 { group = "dictd";
54 description = "DICT.org dictd server";
55 home = "${dictdb}/share/dictd";
56 uid = config.ids.uids.dictd;
57 };
58
59 users.groups.dictd.gid = config.ids.gids.dictd;
60
61 systemd.services.dictd = {
62 description = "DICT.org Dictionary Server";
63 wantedBy = [ "multi-user.target" ];
64 environment = { LOCALE_ARCHIVE = "/run/current-system/sw/lib/locale/locale-archive"; };
65 serviceConfig.Type = "forking";
66 script = "${pkgs.dict}/sbin/dictd -s -c ${dictdb}/share/dictd/dictd.conf --locale en_US.UTF-8";
67 };
68 };
69}