1{ config, lib, pkgs, ... }:
2
3# TODO: This may file may need additional review, eg which configuartions to
4# expose to the user.
5#
6# I only used it to access some simple databases.
7
8# test:
9# isql, then type the following commands:
10# CREATE DATABASE '/var/db/firebird/data/test.fdb' USER 'SYSDBA' PASSWORD 'masterkey';
11# CONNECT '/var/db/firebird/data/test.fdb' USER 'SYSDBA' PASSWORD 'masterkey';
12# CREATE TABLE test ( text varchar(100) );
13# DROP DATABASE;
14#
15# Be careful, virtuoso-opensource also provides a different isql command !
16
17# There are at least two ways to run firebird. superserver has been choosen
18# however there are no strong reasons to prefer this or the other one AFAIK
19# Eg superserver is said to be most efficiently using resources according to
20# http://www.firebirdsql.org/manual/qsg25-classic-or-super.html
21
22with lib;
23
24let
25
26 cfg = config.services.firebird;
27
28 firebird = cfg.package;
29
30 dataDir = "${cfg.baseDir}/data";
31 systemDir = "${cfg.baseDir}/system";
32
33in
34
35{
36
37 ###### interface
38
39 options = {
40
41 services.firebird = {
42
43 enable = mkEnableOption "the Firebird super server";
44
45 package = mkOption {
46 default = pkgs.firebirdSuper;
47 defaultText = "pkgs.firebirdSuper";
48 type = types.package;
49 /*
50 Example: <code>package = pkgs.firebirdSuper.override { icu =
51 pkgs.icu; };</code> which is not recommended for compatibility
52 reasons. See comments at the firebirdSuper derivation
53 */
54
55 description = ''
56 Which firebird derivation to use.
57 '';
58 };
59
60 port = mkOption {
61 default = "3050";
62 type = types.port;
63 description = ''
64 Port Firebird uses.
65 '';
66 };
67
68 user = mkOption {
69 default = "firebird";
70 type = types.str;
71 description = ''
72 User account under which firebird runs.
73 '';
74 };
75
76 baseDir = mkOption {
77 default = "/var/db/firebird"; # ubuntu is using /var/lib/firebird/2.1/data/.. ?
78 type = types.str;
79 description = ''
80 Location containing data/ and system/ directories.
81 data/ stores the databases, system/ stores the password database security2.fdb.
82 '';
83 };
84
85 };
86
87 };
88
89
90 ###### implementation
91
92 config = mkIf config.services.firebird.enable {
93
94 environment.systemPackages = [cfg.package];
95
96 systemd.tmpfiles.rules = [
97 "d '${dataDir}' 0700 ${cfg.user} - - -"
98 "d '${systemDir}' 0700 ${cfg.user} - - -"
99 ];
100
101 systemd.services.firebird =
102 { description = "Firebird Super-Server";
103
104 wantedBy = [ "multi-user.target" ];
105
106 # TODO: moving security2.fdb into the data directory works, maybe there
107 # is a better way
108 preStart =
109 ''
110 if ! test -e "${systemDir}/security2.fdb"; then
111 cp ${firebird}/security2.fdb "${systemDir}"
112 fi
113
114 chmod -R 700 "${dataDir}" "${systemDir}" /var/log/firebird
115 '';
116
117 serviceConfig.User = cfg.user;
118 serviceConfig.LogsDirectory = "firebird";
119 serviceConfig.LogsDirectoryMode = "0700";
120 serviceConfig.ExecStart = "${firebird}/bin/fbserver -d";
121
122 # TODO think about shutdown
123 };
124
125 environment.etc."firebird/firebird.msg".source = "${firebird}/firebird.msg";
126
127 # think about this again - and eventually make it an option
128 environment.etc."firebird/firebird.conf".text = ''
129 # RootDirectory = Restrict ${dataDir}
130 DatabaseAccess = Restrict ${dataDir}
131 ExternalFileAccess = Restrict ${dataDir}
132 # what is this? is None allowed?
133 UdfAccess = None
134 # "Native" = traditional interbase/firebird, "mixed" is windows only
135 Authentication = Native
136
137 # defaults to -1 on non Win32
138 #MaxUnflushedWrites = 100
139 #MaxUnflushedWriteTime = 100
140
141 # show trace if trouble occurs (does this require debug build?)
142 # BugcheckAbort = 0
143 # ConnectionTimeout = 180
144
145 #RemoteServiceName = gds_db
146 RemoteServicePort = ${cfg.port}
147
148 # randomly choose port for server Event Notification
149 #RemoteAuxPort = 0
150 # rsetrict connections to a network card:
151 #RemoteBindAddress =
152 # there are some additional settings which should be reviewed
153 '';
154
155 users.users.firebird = {
156 description = "Firebird server user";
157 group = "firebird";
158 uid = config.ids.uids.firebird;
159 };
160
161 users.groups.firebird.gid = config.ids.gids.firebird;
162
163 };
164}