git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/roundcube: only configure postgres config if localhost is used as database

When using a different database, the evaluation fails as `config.services.postgresql.package` is only set if `services.postgresql` is enabled. Also, the systemd service shouldn't have a relation to postgres if a remote database is used.

commit6b6348eabaaaf37f8d8a99e3e879eff0f4ca6467 authorMaximilian Bosch <maximilian@mbosch.me> dateTue 2 Apr 2019, 16:02 (8 years ago) parent92e5745
1 file changed+24−20
nixos/modules/services/mail/roundcube.nix+24−20
nixos/modules/services/mail/roundcube.nix+24−20
@@ -141,27 +141,31 @@ in
141141
142142 systemd.services.roundcube-setup = let
143143 pgSuperUser = config.services.postgresql.superUser;
144− in {
145− requires = [ "postgresql.service" ];
146− after = [ "postgresql.service" ];
147− wantedBy = [ "multi-user.target" ];
148− path = [ config.services.postgresql.package ];
149− script = ''
150− mkdir -p /var/lib/roundcube
151− if [ ! -f /var/lib/roundcube/db-created ]; then
152− if [ "${cfg.database.host}" = "localhost" ]; then
153− ${pkgs.sudo}/bin/sudo -u ${pgSuperUser} psql postgres -c "create role ${cfg.database.username} with login password '${cfg.database.password}'";
154− ${pkgs.sudo}/bin/sudo -u ${pgSuperUser} psql postgres -c "create database ${cfg.database.dbname} with owner ${cfg.database.username}";
144+ in mkMerge [
145+ (mkIf (cfg.database.host == "localhost") {
146+ requires = [ "postgresql.service" ];
147+ after = [ "postgresql.service" ];
148+ path = [ config.services.postgresql.package ];
149+ })
150+ {
151+ wantedBy = [ "multi-user.target" ];
152+ script = ''
153+ mkdir -p /var/lib/roundcube
154+ if [ ! -f /var/lib/roundcube/db-created ]; then
155+ if [ "${cfg.database.host}" = "localhost" ]; then
156+ ${pkgs.sudo}/bin/sudo -u ${pgSuperUser} psql postgres -c "create role ${cfg.database.username} with login password '${cfg.database.password}'";
157+ ${pkgs.sudo}/bin/sudo -u ${pgSuperUser} psql postgres -c "create database ${cfg.database.dbname} with owner ${cfg.database.username}";
158+ fi
159+ PGPASSWORD=${cfg.database.password} ${pkgs.postgresql}/bin/psql -U ${cfg.database.username} \
160+ -f ${cfg.package}/SQL/postgres.initial.sql \
161+ -h ${cfg.database.host} ${cfg.database.dbname}
162+ touch /var/lib/roundcube/db-created
155163 fi
156− PGPASSWORD=${cfg.database.password} ${pkgs.postgresql}/bin/psql -U ${cfg.database.username} \
157− -f ${cfg.package}/SQL/postgres.initial.sql \
158− -h ${cfg.database.host} ${cfg.database.dbname}
159− touch /var/lib/roundcube/db-created
160− fi
161164
162− ${pkgs.php}/bin/php ${cfg.package}/bin/update.sh
163− '';
164− serviceConfig.Type = "oneshot";
165− };
165+ ${pkgs.php}/bin/php ${cfg.package}/bin/update.sh
166+ '';
167+ serviceConfig.Type = "oneshot";
168+ }
169+ ];
166170 };
167171}