~afontaine/home unlisted

f8f45072e0cfe3dd1c78edb3c015ab62a0fc479e — Andrew Fontaine 23 days ago aa79848 main
Use a URL to Connect to the DB

For actual deployments, a URL is easier to use.
4 files changed, 22 insertions(+), 27 deletions(-)

M apps/blog/lib/release.ex
M apps/blog/mix.exs
M config/releases.exs
M flake.nix
M apps/blog/lib/release.ex => apps/blog/lib/release.ex +4 -0
@@ 27,6 27,10 @@ defmodule Blog.Release do
  end

  defp load_app do
    Application.start(:crypto)
    Application.start(:asn1)
    Application.start(:public_key)
    Application.start(:ssl)
    Application.load(@app)
  end
end

M apps/blog/mix.exs => apps/blog/mix.exs +5 -1
@@ 23,10 23,14 @@ defmodule Blog.MixProject do
  def application do
    [
      mod: {Blog.Application, []},
      extra_applications: [:logger, :runtime_tools]
      extra_applications: extra_applications(Mix.env())
    ]
  end

  defp extra_applications(:prod), do: [:ssl | extra_applications]
  defp extra_applications(_), do: extra_applications
  defp extra_applications(), do: [:logger, :runtime_tools]

  # Specifies which paths to compile per environment.
  defp elixirc_paths(:test), do: ["lib", "test/support"]
  defp elixirc_paths(_), do: ["lib"]

M config/releases.exs => config/releases.exs +8 -13
@@ 4,21 4,16 @@
# remember to add this file to your .gitignore.
import Config

database_socket =
  System.get_env("DATABASE_SOCKET_DIR") ||
    raise """
    environment variable DATABASE_SOCKET_DIR is missing.
    """

database_name =
  System.get_env("DATABASE_NAME") ||
    raise """
    environment variable DATABASE_NAME is missing.
    """
database_url =
  (System.get_env("DATABASE_URL_FILE") ||
     raise("""
     environment variable DATABASE_URL is missing.
     """))
  |> File.read!()
  |> String.trim()

config :blog, Blog.Repo,
  socket_dir: database_socket,
  database: database_name,
  url: database_url,
  pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10")

secret_key_base =

M flake.nix => flake.nix +5 -13
@@ 77,7 77,7 @@
          '';
        };
        packages = let
          version = "0.1.2";
          version = "0.1.3";
          src = ./.;
        in flake-utils.lib.flattenTree {
          home-elixir-deps = erlangPackages.fetchMixDeps {


@@ 159,16 159,10 @@
                  default = "/var/lib/home-web";
                  description = "The directory to write data to";
                };
                databaseName = lib.mkOption {
                  type = lib.types.str;
                  default = "blog_prod";
                  description = "The name of the database to use";
                };
                databaseSocketDir = lib.mkOption {
                databaseUrlFile = lib.mkOption {
                  type = lib.types.path;
                  default = "/run/postgresql";
                  description =
                    "The directory containing the postgres socket to connect with";
                    "A file containing the URL to use to connect to the database";
                };
                user = lib.mkOption {
                  type = lib.types.str;


@@ 222,8 216,7 @@
                    RELEASE_TMP = cfg.dataDir;
                    TZ_DATA_DIR = cfg.dataDir;
                    SECRET_KEY_BASE_FILE = cfg.secretKeyBaseFile;
                    DATABASE_NAME = cfg.databaseName;
                    DATABASE_SOCKET_DIR = cfg.databaseSocketDir;
                    DATABASE_URL_FILE = cfg.databaseUrlFile;
                    HOSTNAME = cfg.host;
                  };
                };


@@ 246,8 239,7 @@
                    POOL_SIZE = builtins.toString cfg.poolSize;
                    SECRET_KEY_BASE_FILE = cfg.secretKeyBaseFile;
                    PORT = builtins.toString cfg.port;
                    DATABASE_NAME = cfg.databaseName;
                    DATABASE_SOCKET_DIR = cfg.databaseSocketDir;
                    DATABASE_URL_FILE = cfg.databaseUrlFile;
                    HOSTNAME = cfg.host;
                  };
                };