copy mobilizonConfig at setup, use writeShellApplication for better runtime checks

This commit is contained in:
778a69cd 2024-03-07 13:00:22 +01:00
parent ec4b6abc4d
commit 6f373f5ea8

View file

@ -95,14 +95,7 @@
let let
pkgs = nixpkgsFor.${system}; pkgs = nixpkgsFor.${system};
settingsFormat = pkgs.formats.elixirConf { }; settingsFormat = pkgs.formats.elixirConf { };
in mobilizonConfig = settingsFormat.generate "runtime.exs" {
{
default =
pkgs.mkShell {
MIX_ENV = "dev";
PGUSER = "mobilizon";
PGDATABASE = "mobilizon";
MOBILIZON_CONFIG_PATH = settingsFormat.generate "runtime.exs" {
":mobilizon" = { ":mobilizon" = {
"Mobilizon.Web.Endpoint" = { "Mobilizon.Web.Endpoint" = {
server = true; server = true;
@ -134,6 +127,13 @@
}; };
}; };
}; };
in
{
default =
pkgs.mkShell {
MIX_ENV = "dev";
PGUSER = "mobilizon";
PGDATABASE = "mobilizon";
buildInputs = buildInputs =
with pkgs; [ with pkgs; [
elixir elixir
@ -142,26 +142,43 @@
imagemagick imagemagick
nodejs nodejs
inotify-tools inotify-tools
(pkgs.writeShellScriptBin "build" '' (pkgs.writeShellApplication {
${elixir}/bin/mix deps.get name = "build";
${elixir}/bin/mix deps.compile runtimeInputs = [ elixir nodejs ];
${elixir}/bin/mix phx.digest text = ''
${nodejs}/bin/npm install mix deps.get
${nodejs}/bin/npm run build mix deps.compile
'') mix phx.digest
(pkgs.writeShellScriptBin "setup" '' npm install
npm run build
'';
})
(pkgs.writeShellApplication {
name = "setup";
runtimeInputs = [ elixir postgresql ];
text = ''
cat ${mobilizonConfig} > config/runtime.exs
# We assume the database already exists # 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;" 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;"
${elixir}/bin/mix ecto.migrate mix ecto.migrate
'') '';
(pkgs.writeShellScriptBin "start" '' })
${elixir}/bin/mix phx.server (pkgs.writeShellApplication {
'') name = "start";
(pkgs.writeShellScriptBin "clean" '' runtimeInputs = [ elixir ];
text = ''
mix phx.server
'';
})
(pkgs.writeShellApplication {
name = "clean";
runtimeInputs = [ postgresql ];
text = ''
rm -rf deps/ _build/ node_modules/ rm -rf deps/ _build/ node_modules/
sudo -u postgres ${postgresql}/bin/psql -c "DROP DATABASE mobilizon;" sudo -u postgres psql -c "DROP DATABASE mobilizon;"
sudo systemctl restart postgresql.service sudo systemctl restart postgresql.service
'') '';
})
]; ];
}; };
}); });