2014-04-14 14:26:48 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2013-10-05 21:07:22 +00:00
|
|
|
|
2023-05-20 02:11:38 +00:00
|
|
|
# TODO: This may file may need additional review, eg which configurations to
|
2013-10-11 15:18:40 +00:00
|
|
|
# expose to the user.
|
|
|
|
#
|
|
|
|
# I only used it to access some simple databases.
|
|
|
|
|
|
|
|
# test:
|
|
|
|
# isql, then type the following commands:
|
|
|
|
# CREATE DATABASE '/var/db/firebird/data/test.fdb' USER 'SYSDBA' PASSWORD 'masterkey';
|
|
|
|
# CONNECT '/var/db/firebird/data/test.fdb' USER 'SYSDBA' PASSWORD 'masterkey';
|
|
|
|
# CREATE TABLE test ( text varchar(100) );
|
|
|
|
# DROP DATABASE;
|
|
|
|
#
|
|
|
|
# Be careful, virtuoso-opensource also provides a different isql command !
|
2013-10-05 21:07:22 +00:00
|
|
|
|
2022-12-18 00:31:14 +00:00
|
|
|
# There are at least two ways to run firebird. superserver has been chosen
|
2013-10-05 21:07:22 +00:00
|
|
|
# however there are no strong reasons to prefer this or the other one AFAIK
|
|
|
|
# Eg superserver is said to be most efficiently using resources according to
|
|
|
|
# http://www.firebirdsql.org/manual/qsg25-classic-or-super.html
|
|
|
|
|
2014-04-14 14:26:48 +00:00
|
|
|
with lib;
|
2013-10-05 21:07:22 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.firebird;
|
|
|
|
|
|
|
|
firebird = cfg.package;
|
|
|
|
|
2013-10-11 15:18:40 +00:00
|
|
|
dataDir = "${cfg.baseDir}/data";
|
|
|
|
systemDir = "${cfg.baseDir}/system";
|
2013-10-05 21:07:22 +00:00
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.firebird = {
|
|
|
|
|
2022-08-28 19:18:44 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "the Firebird super server");
|
2013-10-05 21:07:22 +00:00
|
|
|
|
|
|
|
package = mkOption {
|
2021-05-23 13:53:00 +00:00
|
|
|
default = pkgs.firebird;
|
2021-10-03 16:06:03 +00:00
|
|
|
defaultText = literalExpression "pkgs.firebird";
|
2014-02-27 12:22:04 +00:00
|
|
|
type = types.package;
|
2021-10-03 16:06:03 +00:00
|
|
|
example = literalExpression "pkgs.firebird_3";
|
2022-08-03 20:46:41 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Which Firebird package to be installed: `pkgs.firebird_3`
|
|
|
|
For SuperServer use override: `pkgs.firebird_3.override { superServer = true; };`
|
2013-10-11 15:18:40 +00:00
|
|
|
'';
|
2013-10-05 21:07:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
2021-10-03 16:06:03 +00:00
|
|
|
default = 3050;
|
2019-12-29 22:59:52 +00:00
|
|
|
type = types.port;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2013-10-11 15:18:40 +00:00
|
|
|
Port Firebird uses.
|
|
|
|
'';
|
2013-10-05 21:07:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
default = "firebird";
|
2019-12-29 22:59:52 +00:00
|
|
|
type = types.str;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2013-10-11 15:18:40 +00:00
|
|
|
User account under which firebird runs.
|
|
|
|
'';
|
2013-10-05 21:07:22 +00:00
|
|
|
};
|
|
|
|
|
2013-10-11 15:18:40 +00:00
|
|
|
baseDir = mkOption {
|
2021-05-23 13:53:00 +00:00
|
|
|
default = "/var/lib/firebird";
|
2019-12-29 22:59:52 +00:00
|
|
|
type = types.str;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2013-10-11 15:18:40 +00:00
|
|
|
Location containing data/ and system/ directories.
|
|
|
|
data/ stores the databases, system/ stores the password database security2.fdb.
|
|
|
|
'';
|
2013-10-05 21:07:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf config.services.firebird.enable {
|
|
|
|
|
2013-10-11 15:18:40 +00:00
|
|
|
environment.systemPackages = [cfg.package];
|
2013-10-05 21:07:22 +00:00
|
|
|
|
2019-02-24 21:10:08 +00:00
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d '${dataDir}' 0700 ${cfg.user} - - -"
|
|
|
|
"d '${systemDir}' 0700 ${cfg.user} - - -"
|
|
|
|
];
|
|
|
|
|
2013-10-05 21:07:22 +00:00
|
|
|
systemd.services.firebird =
|
2013-10-11 15:18:40 +00:00
|
|
|
{ description = "Firebird Super-Server";
|
2013-10-05 21:07:22 +00:00
|
|
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
# TODO: moving security2.fdb into the data directory works, maybe there
|
|
|
|
# is a better way
|
|
|
|
preStart =
|
|
|
|
''
|
2013-10-11 15:18:40 +00:00
|
|
|
if ! test -e "${systemDir}/security2.fdb"; then
|
|
|
|
cp ${firebird}/security2.fdb "${systemDir}"
|
2013-10-05 21:07:22 +00:00
|
|
|
fi
|
|
|
|
|
2021-05-23 13:53:00 +00:00
|
|
|
if ! test -e "${systemDir}/security3.fdb"; then
|
|
|
|
cp ${firebird}/security3.fdb "${systemDir}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! test -e "${systemDir}/security4.fdb"; then
|
|
|
|
cp ${firebird}/security4.fdb "${systemDir}"
|
|
|
|
fi
|
|
|
|
|
2013-10-11 15:18:40 +00:00
|
|
|
chmod -R 700 "${dataDir}" "${systemDir}" /var/log/firebird
|
2013-10-05 21:07:22 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
serviceConfig.User = cfg.user;
|
2019-02-24 21:10:08 +00:00
|
|
|
serviceConfig.LogsDirectory = "firebird";
|
|
|
|
serviceConfig.LogsDirectoryMode = "0700";
|
2021-01-24 09:19:10 +00:00
|
|
|
serviceConfig.ExecStart = "${firebird}/bin/fbserver -d";
|
2013-10-05 21:07:22 +00:00
|
|
|
|
|
|
|
# TODO think about shutdown
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.etc."firebird/firebird.msg".source = "${firebird}/firebird.msg";
|
|
|
|
|
|
|
|
# think about this again - and eventually make it an option
|
|
|
|
environment.etc."firebird/firebird.conf".text = ''
|
2013-10-11 15:18:40 +00:00
|
|
|
# RootDirectory = Restrict ${dataDir}
|
|
|
|
DatabaseAccess = Restrict ${dataDir}
|
|
|
|
ExternalFileAccess = Restrict ${dataDir}
|
2013-10-05 21:07:22 +00:00
|
|
|
# what is this? is None allowed?
|
|
|
|
UdfAccess = None
|
|
|
|
# "Native" = traditional interbase/firebird, "mixed" is windows only
|
|
|
|
Authentication = Native
|
|
|
|
|
|
|
|
# defaults to -1 on non Win32
|
|
|
|
#MaxUnflushedWrites = 100
|
|
|
|
#MaxUnflushedWriteTime = 100
|
|
|
|
|
|
|
|
# show trace if trouble occurs (does this require debug build?)
|
|
|
|
# BugcheckAbort = 0
|
|
|
|
# ConnectionTimeout = 180
|
|
|
|
|
|
|
|
#RemoteServiceName = gds_db
|
|
|
|
RemoteServicePort = ${cfg.port}
|
|
|
|
|
|
|
|
# randomly choose port for server Event Notification
|
|
|
|
#RemoteAuxPort = 0
|
|
|
|
# rsetrict connections to a network card:
|
|
|
|
#RemoteBindAddress =
|
2013-10-11 15:18:40 +00:00
|
|
|
# there are some additional settings which should be reviewed
|
2013-10-05 21:07:22 +00:00
|
|
|
'';
|
|
|
|
|
2018-06-29 23:58:35 +00:00
|
|
|
users.users.firebird = {
|
2013-10-25 13:52:52 +00:00
|
|
|
description = "Firebird server user";
|
2013-10-11 15:18:40 +00:00
|
|
|
group = "firebird";
|
|
|
|
uid = config.ids.uids.firebird;
|
|
|
|
};
|
|
|
|
|
2018-06-29 23:58:35 +00:00
|
|
|
users.groups.firebird.gid = config.ids.gids.firebird;
|
2014-07-04 11:48:26 +00:00
|
|
|
|
2013-10-25 13:52:52 +00:00
|
|
|
};
|
2013-10-05 21:07:22 +00:00
|
|
|
}
|