forked from jan-leila/nix-config
		
	refactor: added asseration for db config
This commit is contained in:
		
							parent
							
								
									84b204f8b1
								
							
						
					
					
						commit
						376cb934c3
					
				
					 1 changed files with 54 additions and 14 deletions
				
			
		|  | @ -6,23 +6,40 @@ | ||||||
|   ... |   ... | ||||||
| }: | }: | ||||||
| with lib; let | with lib; let | ||||||
|  |   cfg = config.services.panoramax; | ||||||
|  | 
 | ||||||
|  |   # Database configuration assertions | ||||||
|  |   dbUrlConfigured = cfg.database.url != null; | ||||||
|  |   individualDbConfigured = all (x: x != null) [ | ||||||
|  |     cfg.database.host | ||||||
|  |     cfg.database.port | ||||||
|  |     cfg.database.username | ||||||
|  |     cfg.database.password | ||||||
|  |     cfg.database.name | ||||||
|  |   ]; | ||||||
|  | 
 | ||||||
|   envContent = '' |   envContent = '' | ||||||
|     # Panoramax Configuration |     # Panoramax Configuration | ||||||
|     FLASK_APP=geovisio |     FLASK_APP=geovisio | ||||||
|     ${optionalString (config.services.panoramax.database.url != null) "DB_URL=${config.services.panoramax.database.url}"} |     ${ | ||||||
|     ${optionalString (config.services.panoramax.database.url == null && config.services.panoramax.database.port != null) "DB_PORT=${toString config.services.panoramax.database.port}"} |       if dbUrlConfigured | ||||||
|     ${optionalString (config.services.panoramax.database.url == null && config.services.panoramax.database.host != null) "DB_HOST=${config.services.panoramax.database.host}"} |       then "DB_URL=${cfg.database.url}" | ||||||
|     ${optionalString (config.services.panoramax.database.url == null && config.services.panoramax.database.username != null) "DB_USERNAME=${config.services.panoramax.database.username}"} |       else '' | ||||||
|     ${optionalString (config.services.panoramax.database.url == null && config.services.panoramax.database.password != null) "DB_PASSWORD=${config.services.panoramax.database.password}"} |         DB_HOST=${cfg.database.host} | ||||||
|     ${optionalString (config.services.panoramax.database.url == null && config.services.panoramax.database.name != null) "DB_NAME=${config.services.panoramax.database.name}"} |         DB_PORT=${toString cfg.database.port} | ||||||
|     ${optionalString (config.services.panoramax.storage.fsUrl != null) "FS_URL=${config.services.panoramax.storage.fsUrl}"} |         DB_USERNAME=${cfg.database.username} | ||||||
|     ${optionalString (config.services.panoramax.infrastructure.nbProxies != null) "INFRA_NB_PROXIES=${toString config.services.panoramax.infrastructure.nbProxies}"} |         DB_PASSWORD=${cfg.database.password} | ||||||
|     ${optionalString (config.services.panoramax.flask.secretKey != null) "FLASK_SECRET_KEY=${config.services.panoramax.flask.secretKey}"} |         DB_NAME=${cfg.database.name} | ||||||
|     ${optionalString (config.services.panoramax.flask.sessionCookieDomain != null) "FLASK_SESSION_COOKIE_DOMAIN=${config.services.panoramax.flask.sessionCookieDomain}"} |       '' | ||||||
|     ${optionalString (config.services.panoramax.api.pictures.licenseSpdxId != null) "API_PICTURES_LICENSE_SPDX_ID=${config.services.panoramax.api.pictures.licenseSpdxId}"} |     } | ||||||
|     ${optionalString (config.services.panoramax.api.pictures.licenseUrl != null) "API_PICTURES_LICENSE_URL=${config.services.panoramax.api.pictures.licenseUrl}"} |     ${optionalString (cfg.storage.fsUrl != null) "FS_URL=${cfg.storage.fsUrl}"} | ||||||
|     ${optionalString (config.services.panoramax.port != null) "PORT=${toString config.services.panoramax.port}"} |     ${optionalString (cfg.infrastructure.nbProxies != null) "INFRA_NB_PROXIES=${toString cfg.infrastructure.nbProxies}"} | ||||||
|     ${concatStringsSep "\n" (mapAttrsToList (name: value: "${name}=${value}") config.services.panoramax.extraEnvironment)} |     ${optionalString (cfg.flask.secretKey != null) "FLASK_SECRET_KEY=${cfg.flask.secretKey}"} | ||||||
|  |     ${optionalString (cfg.flask.sessionCookieDomain != null) "FLASK_SESSION_COOKIE_DOMAIN=${cfg.flask.sessionCookieDomain}"} | ||||||
|  |     ${optionalString (cfg.api.pictures.licenseSpdxId != null) "API_PICTURES_LICENSE_SPDX_ID=${cfg.api.pictures.licenseSpdxId}"} | ||||||
|  |     ${optionalString (cfg.api.pictures.licenseUrl != null) "API_PICTURES_LICENSE_URL=${cfg.api.pictures.licenseUrl}"} | ||||||
|  |     ${optionalString (cfg.port != null) "PORT=${toString cfg.port}"} | ||||||
|  |     ${concatStringsSep "\n" (mapAttrsToList (name: value: "${name}=${value}") cfg.extraEnvironment)} | ||||||
|   ''; |   ''; | ||||||
| 
 | 
 | ||||||
|   envFile = pkgs.writeText "panoramax.env" envContent; |   envFile = pkgs.writeText "panoramax.env" envContent; | ||||||
|  | @ -189,6 +206,29 @@ in { | ||||||
|           "d ${config.services.panoramax.storage.fsUrl} 0755 panoramax panoramax -" |           "d ${config.services.panoramax.storage.fsUrl} 0755 panoramax panoramax -" | ||||||
|         ]; |         ]; | ||||||
| 
 | 
 | ||||||
|  |         assertions = [ | ||||||
|  |           { | ||||||
|  |             assertion = dbUrlConfigured || individualDbConfigured; | ||||||
|  |             message = '' | ||||||
|  |               Panoramax database configuration requires either: | ||||||
|  |               - A complete database URL (services.panoramax.database.url), OR | ||||||
|  |               - All individual database options (host, port, username, password, name) | ||||||
|  | 
 | ||||||
|  |               Currently configured: | ||||||
|  |               - database.url: ${ | ||||||
|  |                 if dbUrlConfigured | ||||||
|  |                 then "✓ configured" | ||||||
|  |                 else "✗ not configured" | ||||||
|  |               } | ||||||
|  |               - individual options: ${ | ||||||
|  |                 if individualDbConfigured | ||||||
|  |                 then "✓ all configured" | ||||||
|  |                 else "✗ some missing" | ||||||
|  |               } | ||||||
|  |             ''; | ||||||
|  |           } | ||||||
|  |         ]; | ||||||
|  | 
 | ||||||
|         # TODO: auto config db |         # TODO: auto config db | ||||||
|       } |       } | ||||||
|       ( |       ( | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue