A fork of attic a self-hostable Nix Binary Cache server
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #13 from DarkKirb/env-config

Add support for reading database url from environment variable

authored by

Zhaofeng Li and committed by
GitHub
70ae61b5 1750c4be

+11 -1
+2 -1
nixos/atticd.nix
··· 17 17 cat $configFile 18 18 19 19 export ATTIC_SERVER_TOKEN_HS256_SECRET_BASE64="dGVzdCBzZWNyZXQ=" 20 + export ATTIC_SERVER_DATABASE_URL="sqlite://:memory:" 20 21 ${cfg.package}/bin/atticd --mode check-config -f $configFile 21 22 cat <$configFile >$out 22 23 ''; ··· 36 37 ''; 37 38 38 39 hasLocalPostgresDB = let 39 - url = cfg.settings.database.url; 40 + url = cfg.settings.database.url or ""; 40 41 localStrings = [ "localhost" "127.0.0.1" "/run/postgresql" ]; 41 42 hasLocalStrings = lib.any (lib.flip lib.hasInfix url) localStrings; 42 43 in config.services.postgresql.enable && lib.hasPrefix "postgresql://" url && hasLocalStrings;
+9
server/src/config.rs
··· 28 28 /// Environment variable storing the Base64-encoded HS256 JWT secret. 29 29 const ENV_TOKEN_HS256_SECRET_BASE64: &str = "ATTIC_SERVER_TOKEN_HS256_SECRET_BASE64"; 30 30 31 + /// Environment variable storing the database connection string. 32 + const ENV_DATABASE_URL: &str = "ATTIC_SERVER_DATABASE_URL"; 33 + 31 34 /// Configuration for the Attic Server. 32 35 #[derive(Clone, Derivative, Deserialize)] 33 36 #[derivative(Debug)] ··· 118 121 #[derive(Debug, Clone, Deserialize)] 119 122 pub struct DatabaseConfig { 120 123 /// Connection URL. 124 + #[serde(default = "load_database_url_from_env")] 121 125 pub url: String, 122 126 123 127 /// Whether to enable sending of periodic heartbeat queries. ··· 240 244 .expect("The HS256 secret must be specified in either token_hs256_secret or the ATTIC_SERVER_TOKEN_HS256_SECRET_BASE64 environment."); 241 245 242 246 decode_token_hs256_secret_base64(&s).expect("Failed to load as decoding key") 247 + } 248 + 249 + fn load_database_url_from_env() -> String { 250 + env::var(ENV_DATABASE_URL) 251 + .expect("Database URL must be specified in either database.url or the ATTIC_SERVER_DATABASE_URL environment.") 243 252 } 244 253 245 254 impl CompressionConfig {