development environment for flake

This commit is contained in:
778a69cd 2024-03-05 17:10:04 +01:00
parent 561677ce3a
commit 989158ef4d

116
flake.nix
View file

@ -92,20 +92,118 @@
});
devShells = forAllSystems (system:
let pkgs = nixpkgsFor.${system};
in {
let
pkgs = nixpkgsFor.${system};
settingsFormat = pkgs.formats.elixirConf { };
in
{
default =
pkgs.mkShell {
buildInputs = with pkgs; [
elixir
mix2nix
cmake
imagemagick
nodejs
];
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
mix2nix
cmake
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" ''
${elixir}/bin/mix ecto.create
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
'')
];
};
});
nixosModules.devSetup = { config, lib, pkgs, ... }:
let
cfg = config.mobilizonDevEnvironment;
in
{
options.mobilizonDevEnvironment = {
enable = lib.mkEnableOption
(lib.mdDoc "development environment for Mobilizon");
user = lib.mkOption {
type = lib.types.str;
description = "Unix user that runs the backend application to connect to the database";
};
};
config = lib.mkIf cfg.enable {
services.postgresql = {
enable = true;
ensureDatabases = [ "mobilizon" ];
ensureUsers = [
{
name = "mobilizon";
ensureDBOwnership = true;
}
];
extraPlugins = with config.services.postgresql.package.pkgs; [ postgis ];
identMap = ''
map-mobilizon ${cfg.user} mobilizon
'';
authentication = ''
local all mobilizon ident map=map-mobilizon
'';
};
};
};
overlays.default = final: prev: {
inherit (self.packages."${prev.system}") mobilizon;
};