From 12e04d839e27afb8bd5de558c3bb6ef2209cc209 Mon Sep 17 00:00:00 2001 From: 778a69cd <778a69cd@potsda.mn> Date: Thu, 7 Mar 2024 13:00:22 +0100 Subject: [PATCH] copy mobilizonConfig at setup, use writeShellApplication for better runtime checks --- flake.nix | 121 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 69 insertions(+), 52 deletions(-) diff --git a/flake.nix b/flake.nix index 92b741fcc..e22e08f7a 100644 --- a/flake.nix +++ b/flake.nix @@ -98,6 +98,38 @@ let pkgs = nixpkgsFor.${system}; settingsFormat = pkgs.formats.elixirConf { }; + mobilizonConfig = settingsFormat.generate "runtime.exs" { + ":mobilizon" = { + "Mobilizon.Web.Endpoint" = { + server = true; + url.host = "mobilizon.dev"; + http = { + ip = settingsFormat.lib.mkTuple [ 0 0 0 0 0 0 0 1 ]; + port = 4000; + }; + secret_key_base = + "2q/l1WDx3RQQy7gZ1k001//6nc66moWUEJQyGuMK/z3zPLYW6FYtIgCkUzGP0+X/"; + }; + "Mobilizon.Web.Auth.Guardian" = { + secret_key = "N8x7/tf0kInLFS2poO22g6OGPiMjSrDEhmk29nFqV35q7hQ0DtBt/cRYCsqBNp2L"; + }; + ":instance" = { + name = "Mobilizon"; + description = "Change this to a proper description of your instance"; + hostname = "mobilizon.dev"; + registrations_open = true; + email_from = "noreply@mobilizon.dev"; + email_reply_to = "noreply@mobilizon.dev"; + }; + "Mobilizon.Storage.Repo" = { + adapter = settingsFormat.lib.mkAtom "Ecto.Adapters.Postgres"; + pool_size = 10; + username = "mobilizon"; + database = "mobilizon"; + socket_dir = "/var/run/postgresql"; + }; + }; + }; in { default = @@ -105,38 +137,6 @@ MIX_ENV = "dev"; PGUSER = "mobilizon"; PGDATABASE = "mobilizon"; - MOBILIZON_CONFIG_PATH = settingsFormat.generate "runtime.exs" { - ":mobilizon" = { - "Mobilizon.Web.Endpoint" = { - server = true; - url.host = "mobilizon.dev"; - http = { - ip = settingsFormat.lib.mkTuple [ 0 0 0 0 0 0 0 1 ]; - port = 4000; - }; - secret_key_base = - "2q/l1WDx3RQQy7gZ1k001//6nc66moWUEJQyGuMK/z3zPLYW6FYtIgCkUzGP0+X/"; - }; - "Mobilizon.Web.Auth.Guardian" = { - secret_key = "N8x7/tf0kInLFS2poO22g6OGPiMjSrDEhmk29nFqV35q7hQ0DtBt/cRYCsqBNp2L"; - }; - ":instance" = { - name = "Mobilizon"; - description = "Change this to a proper description of your instance"; - hostname = "mobilizon.dev"; - registrations_open = true; - email_from = "noreply@mobilizon.dev"; - email_reply_to = "noreply@mobilizon.dev"; - }; - "Mobilizon.Storage.Repo" = { - adapter = settingsFormat.lib.mkAtom "Ecto.Adapters.Postgres"; - pool_size = 10; - username = "mobilizon"; - database = "mobilizon"; - socket_dir = "/var/run/postgresql"; - }; - }; - }; buildInputs = with pkgs; [ elixir @@ -145,26 +145,43 @@ imagemagick nodejs inotify-tools - (pkgs.writeShellScriptBin "build" '' - ${elixir}/bin/mix deps.get - ${elixir}/bin/mix deps.compile - ${elixir}/bin/mix phx.digest - ${nodejs}/bin/npm install - ${nodejs}/bin/npm run build - '') - (pkgs.writeShellScriptBin "setup" '' - # We assume the database already exists - sudo -u postgres ${postgresql}/bin/psql -d mobilizon -c "create extension if not exists postgis; create extension if not exists unaccent; create extension if not exists pg_trgm;" - ${elixir}/bin/mix ecto.migrate - '') - (pkgs.writeShellScriptBin "start" '' - ${elixir}/bin/mix phx.server - '') - (pkgs.writeShellScriptBin "clean" '' - rm -rf deps/ _build/ node_modules/ - sudo -u postgres ${postgresql}/bin/psql -c "DROP DATABASE mobilizon;" - sudo systemctl restart postgresql.service - '') + (pkgs.writeShellApplication { + name = "build"; + runtimeInputs = [ elixir nodejs ]; + text = '' + mix deps.get + mix deps.compile + mix phx.digest + npm install + npm run build + ''; + }) + (pkgs.writeShellApplication { + name = "setup"; + runtimeInputs = [ elixir postgresql ]; + text = '' + cat ${mobilizonConfig} > config/runtime.exs + # We assume the database already exists + sudo -u postgres psql -d mobilizon -c "create extension if not exists postgis; create extension if not exists unaccent; create extension if not exists pg_trgm;" + mix ecto.migrate + ''; + }) + (pkgs.writeShellApplication { + name = "start"; + runtimeInputs = [ elixir ]; + text = '' + mix phx.server + ''; + }) + (pkgs.writeShellApplication { + name = "clean"; + runtimeInputs = [ postgresql ]; + text = '' + rm -rf deps/ _build/ node_modules/ + sudo -u postgres psql -c "DROP DATABASE mobilizon;" + sudo systemctl restart postgresql.service + ''; + }) ]; }; });