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