20 cfg = config.services.engelsystem;
23 (mkRenamedOptionModule [ "services" "engelsystem" "config" ] [ "services" "engelsystem" "settings" ])
26 options.services.engelsystem = {
27 enable = mkEnableOption "engelsystem, an online tool for coordinating volunteers and shifts on large events";
29 package = mkPackageOption pkgs "engelsystem" { };
33 example = "engelsystem.example.com";
34 description = "Domain to serve on.";
37 createDatabase = mkOption {
41 Whether to create a local database automatically.
42 This will override every database setting in {option}`services.engelsystem.config`.
51 database = "engelsystem";
52 username = "engelsystem";
58 host = "database.example.com";
59 database = "engelsystem";
60 username = "engelsystem";
61 password._secret = "/var/keys/engelsystem/database";
65 host = "smtp.example.com";
67 from.address = "engelsystem@example.com";
68 from.name = "example engelsystem";
70 username = "engelsystem@example.com";
71 password._secret = "/var/keys/engelsystem/mail";
74 min_password_length = 6;
75 default_locale = "de_DE";
78 Options to be added to config.php, as a nix attribute set. Options containing secret data
79 should be set to an attribute set containing the attribute _secret - a string pointing to a
80 file containing the value the option should be set to. See the example to get a better
81 picture of this: in the resulting config.php file, the email.password key will be set to
82 the contents of the /var/keys/engelsystem/mail file.
84 See https://engelsystem.de/doc/admin/configuration/ for available options.
86 Note that the admin user login credentials cannot be set here - they always default to
87 admin:asdfasdf. Log in and change them immediately.
92 config = mkIf cfg.enable {
94 services.mysql = mkIf cfg.createDatabase {
96 package = mkDefault pkgs.mariadb;
99 ensurePermissions = { "engelsystem.*" = "ALL PRIVILEGES"; };
101 ensureDatabases = [ "engelsystem" ];
104 environment.etc."engelsystem/config.php".source =
105 pkgs.writeText "config.php" ''
107 return json_decode(file_get_contents("/var/lib/engelsystem/config.json"), true);
110 services.phpfpm.pools.engelsystem = {
111 user = "engelsystem";
113 "listen.owner" = config.services.nginx.user;
115 "pm.max_children" = 32;
116 "pm.max_requests" = 500;
117 "pm.start_servers" = 2;
118 "pm.min_spare_servers" = 2;
119 "pm.max_spare_servers" = 5;
120 "php_admin_value[error_log]" = "stderr";
121 "php_admin_flag[log_errors]" = true;
122 "catch_workers_output" = true;
128 virtualHosts."${cfg.domain}".locations = {
130 root = "${cfg.package}/share/engelsystem/public";
133 try_files $uri $uri/ /index.php?$args;
138 root = "${cfg.package}/share/engelsystem/public";
140 fastcgi_pass unix:${config.services.phpfpm.pools.engelsystem.socket};
141 fastcgi_index index.php;
142 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
143 include ${config.services.nginx.package}/conf/fastcgi_params;
144 include ${config.services.nginx.package}/conf/fastcgi.conf;
150 systemd.services."engelsystem-init" = {
151 wantedBy = [ "multi-user.target" ];
152 serviceConfig = { Type = "oneshot"; };
155 genConfigScript = pkgs.writeScript "engelsystem-gen-config.sh"
156 (utils.genJqSecretsReplacementSnippet cfg.settings "config.json");
159 mkdir -p /var/lib/engelsystem/storage/app
160 mkdir -p /var/lib/engelsystem/storage/cache/views
161 cd /var/lib/engelsystem
163 chmod 400 config.json
164 chown -R engelsystem .
167 systemd.services."engelsystem-migrate" = {
168 wantedBy = [ "multi-user.target" ];
171 User = "engelsystem";
172 Group = "engelsystem";
175 versionFile="/var/lib/engelsystem/.version"
176 version=$(cat "$versionFile" 2>/dev/null || echo 0)
178 if [[ $version != ${cfg.package.version} ]]; then
179 # prune template cache between releases
180 rm -rfv /var/lib/engelsystem/storage/cache/*
182 ${cfg.package}/bin/migrate
184 echo ${cfg.package.version} > "$versionFile"
187 after = [ "engelsystem-init.service" "mysql.service" ];
189 systemd.services."phpfpm-engelsystem".after =
190 [ "engelsystem-migrate.service" ];
192 users.users.engelsystem = {
195 home = "/var/lib/engelsystem/storage";
196 group = "engelsystem";
198 users.groups.engelsystem = { };