20 cfg = config.services.engelsystem;
24 (mkRenamedOptionModule
25 [ "services" "engelsystem" "config" ]
26 [ "services" "engelsystem" "settings" ]
30 options.services.engelsystem = {
31 enable = mkEnableOption "engelsystem, an online tool for coordinating volunteers and shifts on large events";
33 package = mkPackageOption pkgs "engelsystem" { };
37 example = "engelsystem.example.com";
38 description = "Domain to serve on.";
41 createDatabase = mkOption {
45 Whether to create a local database automatically.
46 This will override every database setting in {option}`services.engelsystem.config`.
55 database = "engelsystem";
56 username = "engelsystem";
62 host = "database.example.com";
63 database = "engelsystem";
64 username = "engelsystem";
65 password._secret = "/var/keys/engelsystem/database";
69 host = "smtp.example.com";
71 from.address = "engelsystem@example.com";
72 from.name = "example engelsystem";
74 username = "engelsystem@example.com";
75 password._secret = "/var/keys/engelsystem/mail";
78 min_password_length = 6;
79 default_locale = "de_DE";
82 Options to be added to config.php, as a nix attribute set. Options containing secret data
83 should be set to an attribute set containing the attribute _secret - a string pointing to a
84 file containing the value the option should be set to. See the example to get a better
85 picture of this: in the resulting config.php file, the email.password key will be set to
86 the contents of the /var/keys/engelsystem/mail file.
88 See https://engelsystem.de/doc/admin/configuration/ for available options.
90 Note that the admin user login credentials cannot be set here - they always default to
91 admin:asdfasdf. Log in and change them immediately.
96 config = mkIf cfg.enable {
98 services.mysql = mkIf cfg.createDatabase {
100 package = mkDefault pkgs.mariadb;
103 name = "engelsystem";
104 ensurePermissions = {
105 "engelsystem.*" = "ALL PRIVILEGES";
109 ensureDatabases = [ "engelsystem" ];
112 environment.etc."engelsystem/config.php".source = pkgs.writeText "config.php" ''
114 return json_decode(file_get_contents("/var/lib/engelsystem/config.json"), true);
117 services.phpfpm.pools.engelsystem = {
118 user = "engelsystem";
120 "listen.owner" = config.services.nginx.user;
122 "pm.max_children" = 32;
123 "pm.max_requests" = 500;
124 "pm.start_servers" = 2;
125 "pm.min_spare_servers" = 2;
126 "pm.max_spare_servers" = 5;
127 "php_admin_value[error_log]" = "stderr";
128 "php_admin_flag[log_errors]" = true;
129 "catch_workers_output" = true;
135 virtualHosts."${cfg.domain}".locations = {
137 root = "${cfg.package}/share/engelsystem/public";
140 try_files $uri $uri/ /index.php?$args;
145 root = "${cfg.package}/share/engelsystem/public";
147 fastcgi_pass unix:${config.services.phpfpm.pools.engelsystem.socket};
148 fastcgi_index index.php;
149 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
150 include ${config.services.nginx.package}/conf/fastcgi_params;
151 include ${config.services.nginx.package}/conf/fastcgi.conf;
157 systemd.services."engelsystem-init" = {
158 wantedBy = [ "multi-user.target" ];
164 genConfigScript = pkgs.writeScript "engelsystem-gen-config.sh" (
165 utils.genJqSecretsReplacementSnippet cfg.settings "config.json"
170 mkdir -p /var/lib/engelsystem/storage/app
171 mkdir -p /var/lib/engelsystem/storage/cache/views
172 cd /var/lib/engelsystem
174 chmod 400 config.json
175 chown -R engelsystem .
178 systemd.services."engelsystem-migrate" = {
179 wantedBy = [ "multi-user.target" ];
182 User = "engelsystem";
183 Group = "engelsystem";
186 versionFile="/var/lib/engelsystem/.version"
187 version=$(cat "$versionFile" 2>/dev/null || echo 0)
189 if [[ $version != ${cfg.package.version} ]]; then
190 # prune template cache between releases
191 rm -rfv /var/lib/engelsystem/storage/cache/*
193 ${cfg.package}/bin/migrate
195 echo ${cfg.package.version} > "$versionFile"
199 "engelsystem-init.service"
203 systemd.services."phpfpm-engelsystem".after = [ "engelsystem-migrate.service" ];
205 users.users.engelsystem = {
208 home = "/var/lib/engelsystem/storage";
209 group = "engelsystem";
211 users.groups.engelsystem = { };