-defmodule Pleroma.Config.Loader do
- # TODO: add support for releases
- if Code.ensure_loaded?(Config.Reader) do
- @spec load() :: map()
- def load do
- config = load("config/config.exs")
- env_config = load("config/#{Mix.env()}.exs")
-
- Config.Reader.merge(config, env_config)
- end
-
- @spec load(Path.t()) :: keyword()
- def load(path), do: Config.Reader.read!(path)
- else
- # support for Elixir less than 1.9
- @spec load() :: map()
- def load do
- config = load("config/config.exs")
- env_config = load("config/#{Mix.env()}.exs")
-
- Mix.Config.merge(config, env_config)
- end
-
- @spec load(Path.t()) :: keyword()
- def load(path) do
- {config, _paths} = Mix.Config.eval!(path)
- config
- end
- end
-end
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Config.Holder do
- @config Pleroma.Config.Loader.load()
-
- @spec config() :: keyword()
- def config do
- @config
- |> Keyword.keys()
- |> Enum.map(&filter(&1, config(&1)))
- |> List.flatten()
+ @config Pleroma.Config.Loader.default_config()
+
+ @spec save_default() :: :ok
+ def save_default do
+ default_config =
+ if System.get_env("RELEASE_NAME") do
+ Pleroma.Config.Loader.merge(@config, release_defaults())
+ else
+ @config
+ end
+
+ Pleroma.Config.put(:default_config, default_config)
end
- @spec config(atom()) :: any()
- def config(group), do: @config[group]
+ @spec default_config() :: keyword()
+ def default_config, do: get_default()
- @spec config(atom(), atom()) :: any()
- def config(group, key), do: @config[group][key]
+ @spec default_config(atom()) :: keyword()
+ def default_config(group), do: Keyword.get(get_default(), group)
- defp filter(group, settings) when group not in [:swarm] do
- filtered =
- Enum.reject(settings, fn {k, _v} ->
- k in [Pleroma.Repo, Pleroma.Web.Endpoint, :env, :configurable_from_database] or
- (group == :phoenix and k == :serve_endpoints)
- end)
+ @spec default_config(atom(), atom()) :: keyword()
+ def default_config(group, key), do: get_in(get_default(), [group, key])
- {group, filtered}
- end
+ defp get_default, do: Pleroma.Config.get(:default_config)
- defp filter(_, _), do: []
+ @spec release_defaults() :: keyword()
+ def release_defaults do
+ [
+ pleroma: [
+ {:instance, [static_dir: "/var/lib/pleroma/static"]},
+ {Pleroma.Uploaders.Local, [uploads: "/var/lib/pleroma/uploads"]},
+ {:modules, [runtime_dir: "/var/lib/pleroma/modules"]},
+ {:release, true}
+ ]
+ ]
+ end
end