at 23.11-pre 4.7 kB view raw
1{ config, lib, pkgs, ... }: 2 3# TODO: This may file may need additional review, eg which configurations 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 chosen 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 (lib.mdDoc "the Firebird super server"); 44 45 package = mkOption { 46 default = pkgs.firebird; 47 defaultText = literalExpression "pkgs.firebird"; 48 type = types.package; 49 example = literalExpression "pkgs.firebird_3"; 50 description = lib.mdDoc '' 51 Which Firebird package to be installed: `pkgs.firebird_3` 52 For SuperServer use override: `pkgs.firebird_3.override { superServer = true; };` 53 ''; 54 }; 55 56 port = mkOption { 57 default = 3050; 58 type = types.port; 59 description = lib.mdDoc '' 60 Port Firebird uses. 61 ''; 62 }; 63 64 user = mkOption { 65 default = "firebird"; 66 type = types.str; 67 description = lib.mdDoc '' 68 User account under which firebird runs. 69 ''; 70 }; 71 72 baseDir = mkOption { 73 default = "/var/lib/firebird"; 74 type = types.str; 75 description = lib.mdDoc '' 76 Location containing data/ and system/ directories. 77 data/ stores the databases, system/ stores the password database security2.fdb. 78 ''; 79 }; 80 81 }; 82 83 }; 84 85 86 ###### implementation 87 88 config = mkIf config.services.firebird.enable { 89 90 environment.systemPackages = [cfg.package]; 91 92 systemd.tmpfiles.rules = [ 93 "d '${dataDir}' 0700 ${cfg.user} - - -" 94 "d '${systemDir}' 0700 ${cfg.user} - - -" 95 ]; 96 97 systemd.services.firebird = 98 { description = "Firebird Super-Server"; 99 100 wantedBy = [ "multi-user.target" ]; 101 102 # TODO: moving security2.fdb into the data directory works, maybe there 103 # is a better way 104 preStart = 105 '' 106 if ! test -e "${systemDir}/security2.fdb"; then 107 cp ${firebird}/security2.fdb "${systemDir}" 108 fi 109 110 if ! test -e "${systemDir}/security3.fdb"; then 111 cp ${firebird}/security3.fdb "${systemDir}" 112 fi 113 114 if ! test -e "${systemDir}/security4.fdb"; then 115 cp ${firebird}/security4.fdb "${systemDir}" 116 fi 117 118 chmod -R 700 "${dataDir}" "${systemDir}" /var/log/firebird 119 ''; 120 121 serviceConfig.User = cfg.user; 122 serviceConfig.LogsDirectory = "firebird"; 123 serviceConfig.LogsDirectoryMode = "0700"; 124 serviceConfig.ExecStart = "${firebird}/bin/fbserver -d"; 125 126 # TODO think about shutdown 127 }; 128 129 environment.etc."firebird/firebird.msg".source = "${firebird}/firebird.msg"; 130 131 # think about this again - and eventually make it an option 132 environment.etc."firebird/firebird.conf".text = '' 133 # RootDirectory = Restrict ${dataDir} 134 DatabaseAccess = Restrict ${dataDir} 135 ExternalFileAccess = Restrict ${dataDir} 136 # what is this? is None allowed? 137 UdfAccess = None 138 # "Native" = traditional interbase/firebird, "mixed" is windows only 139 Authentication = Native 140 141 # defaults to -1 on non Win32 142 #MaxUnflushedWrites = 100 143 #MaxUnflushedWriteTime = 100 144 145 # show trace if trouble occurs (does this require debug build?) 146 # BugcheckAbort = 0 147 # ConnectionTimeout = 180 148 149 #RemoteServiceName = gds_db 150 RemoteServicePort = ${cfg.port} 151 152 # randomly choose port for server Event Notification 153 #RemoteAuxPort = 0 154 # rsetrict connections to a network card: 155 #RemoteBindAddress = 156 # there are some additional settings which should be reviewed 157 ''; 158 159 users.users.firebird = { 160 description = "Firebird server user"; 161 group = "firebird"; 162 uid = config.ids.uids.firebird; 163 }; 164 165 users.groups.firebird.gid = config.ids.gids.firebird; 166 167 }; 168}