1{ config, lib, pkgs, ... }:
2let
3 cfg = config.services.virtuoso;
4 virtuosoUser = "virtuoso";
5 stateDir = "/var/lib/virtuoso";
6in
7with lib;
8{
9
10 ###### interface
11
12 options = {
13
14 services.virtuoso = {
15
16 enable = mkEnableOption "Virtuoso Opensource database server";
17
18 config = mkOption {
19 type = types.lines;
20 default = "";
21 description = "Extra options to put into Virtuoso configuration file.";
22 };
23
24 parameters = mkOption {
25 type = types.lines;
26 default = "";
27 description = "Extra options to put into [Parameters] section of Virtuoso configuration file.";
28 };
29
30 listenAddress = mkOption {
31 type = types.str;
32 default = "1111";
33 example = "myserver:1323";
34 description = "ip:port or port to listen on.";
35 };
36
37 httpListenAddress = mkOption {
38 type = types.nullOr types.str;
39 default = null;
40 example = "myserver:8080";
41 description = "ip:port or port for Virtuoso HTTP server to listen on.";
42 };
43
44 dirsAllowed = mkOption {
45 type = types.nullOr types.str; # XXX Maybe use a list in the future?
46 default = null;
47 example = "/www, /home/";
48 description = "A list of directories Virtuoso is allowed to access";
49 };
50 };
51
52 };
53
54
55 ###### implementation
56
57 config = mkIf cfg.enable {
58
59 users.users.${virtuosoUser} =
60 { uid = config.ids.uids.virtuoso;
61 description = "virtuoso user";
62 home = stateDir;
63 };
64
65 systemd.services.virtuoso = {
66 after = [ "network.target" ];
67 wantedBy = [ "multi-user.target" ];
68
69 preStart = ''
70 mkdir -p ${stateDir}
71 chown ${virtuosoUser} ${stateDir}
72 '';
73
74 script = ''
75 cd ${stateDir}
76 ${pkgs.virtuoso}/bin/virtuoso-t +foreground +configfile ${pkgs.writeText "virtuoso.ini" cfg.config}
77 '';
78 };
79
80 services.virtuoso.config = ''
81 [Database]
82 DatabaseFile=${stateDir}/x-virtuoso.db
83 TransactionFile=${stateDir}/x-virtuoso.trx
84 ErrorLogFile=${stateDir}/x-virtuoso.log
85 xa_persistent_file=${stateDir}/x-virtuoso.pxa
86
87 [Parameters]
88 ServerPort=${cfg.listenAddress}
89 RunAs=${virtuosoUser}
90 ${optionalString (cfg.dirsAllowed != null) "DirsAllowed=${cfg.dirsAllowed}"}
91 ${cfg.parameters}
92
93 [HTTPServer]
94 ${optionalString (cfg.httpListenAddress != null) "ServerPort=${cfg.httpListenAddress}"}
95 '';
96
97 };
98
99}