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 = ''
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 = "with pkgs.dictdDBs; [ wiktionary wordnet ]";
29 example = literalExample "[ pkgs.dictdDBs.nld2eng ]";
30 description = ''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 users.extraUsers = singleton
49 { name = "dictd";
50 group = "dictd";
51 description = "DICT.org dictd server";
52 home = "${dictdb}/share/dictd";
53 uid = config.ids.uids.dictd;
54 };
55
56 users.extraGroups = singleton
57 { name = "dictd";
58 gid = config.ids.gids.dictd;
59 };
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}