Skip to content

Commit

Permalink
Fix tzdata not writable errors when running from flake
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmay committed Mar 19, 2024
1 parent 221c366 commit 06af618
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,5 @@ end
config :teslamate, :srtm_cache, System.get_env("SRTM_CACHE", ".srtm_cache")

config :teslamate, TeslaMate.Vault, key: Util.get_env("ENCRYPTION_KEY", test: "secret")

config :tzdata, :data_dir, System.get_env("TZDATA_DIR")
22 changes: 21 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@

};

postgres_port = 7000;
mosquitto_port = 7001;

psql = pkgs.writeShellScriptBin "teslamate_psql" ''
exec "${pkgs.postgresql}/bin/psql" --host "$DATABASE_HOST" --user "$DATABASE_USER" --port "$DATABASE_PORT" "$DATABASE_NAME" "$@"
'';
mosquitto_sub = pkgs.writeShellScriptBin "teslamate_sub" ''
exec "${pkgs.mosquitto}/bin/mosquitto_sub" -h "$MQTT_HOST" -p "$MQTT_PORT" -u "$MQTT_USERNAME" -P "$MQTT_PASSWORD" "$@"
'';

in with pkgs; {
packages.default = pkg;
devShells.default = devenv.lib.mkShell {
Expand All @@ -96,6 +106,9 @@
prefetch-npm-deps
# for dashboard scripts
jq
psql
mosquitto
mosquitto_sub
] ++ optional stdenv.isLinux inotify-tools
++ optional stdenv.isDarwin terminal-notifier
++ optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [
Expand All @@ -112,14 +125,21 @@
export DATABASE_PASS="your_secure_password_here"
export DATABASE_NAME="teslamate"
export DATABASE_HOST="127.0.0.1"
export DATABASE_PORT="${toString postgres_port}"
export MQTT_HOST="127.0.0.1"
export MQTT_PORT="${toString mosquitto_port}"
export RELEASE_COOKIE="1234567890123456789"
export TZDATA_DIR="$PWD/tzdata"
'';
processes.mqtt = { exec = "${pkgs.mosquitto}/bin/mosquitto"; };
processes.mqtt = {
exec =
"${pkgs.mosquitto}/bin/mosquitto -p ${toString mosquitto_port}";
};
services.postgres = {
enable = true;
package = pkgs.postgresql_15;
listen_addresses = "127.0.0.1";
port = postgres_port;
initialDatabases = [{ name = "teslamate"; }];
initialScript = ''
CREATE USER teslamate with encrypted password 'your_secure_password_here';
Expand Down

0 comments on commit 06af618

Please sign in to comment.