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