Klimatkalendern is an event calendar for all activities in Sweden (or elsewhere) that aims to promote sustainablility.
This git repo is a detached Mobilizon fork repurposed to serve klimatkalendern.nu. The fork diverges from Mobilizon 5.1.2 with changes tailored to our specific use case. As a consequence, this project is currently of limited use outside klimatkalendern.nu.
This README contains instructions for setting up the project locally, if you want to know more about Klimatkalendern, visit klimatkalendern.nu.
Contributors are much welcome, we could use extra eyes on this. If you want to restore a state for testing and development, but don't have access to our storage, email us at info@klimatkalendern.nu.
Ensure you have a machine running either linux, macOS or wsl with git installed, then:
Clone this repo:
bash git clone https://github.com/kompismoln/klimatkalendern cd klimatkalendern
Nix is used to manage the build and deployment pipeline.
Although not strictly necessary for development, it's highly recommended.
Nix ensures all system dependencies have the correct versions and enables you to test
the production build process, verifying it will work as expected.
If you don't want to use nix for some reason, all system dependencies are specified
in flake.nix under devShell.
-
Install Nix with flake support:
We recommend the lix.systems implementation as it allows flakes to be enabled during install.
Follow the instructions on their respective websites.
-
Enter Development Environment:
Within the cloned repository, run:
nix develop
This command sets up an environment with all the necessary dependencies.
Note on
nix developvsnix-direnv: Usingnix developworks, but it's not always convenient as you'll need to exit and re-enter the shell when switching branches or ifflake.nixis updated. To ensure that the environment is automatically updated when youcdinto the project directory, consider using nix-direnv. Follow its installation instructions to set it up.
This step will generate config/runtime.exs which is used to configure
the local mobilizon instance.
First run:
mix deps.get # Install elixir dependencies
mix mobilizon.instance gen # Generate server configuration
Then answer the following for the questions prompted:
What domain will your instance use? (e.g mobilizon.org) [] localhost
What is the name of your instance? (e.g. Mobilizon) [] klimatkalendern
What's the address email will be send with? [noreply@localhost]
What is the hostname of your database? [localhost]
What is the name of your database? [mobilizon_prod] klimatkalendern
What is the user used to connect to your database? [mobilizon] klimatkalendern
What is the password used to connect to your database? [autogenerated] klimatkalendern
What port will the app listen to (leave it if you are using the default setup with nginx)? [4000]
You'll need a PostgreSQL database with the PostGIS extension. This setup assumes PostgreSQL is managed at the OS level.
1. Install PostgreSQL and PostGIS:
-
For Debian-based Linux:
sudo apt update sudo apt install postgresql postgresql-contrib postgis # On some systems, PostGIS might be versioned, e.g., postgresql-15-postgis-3 # You may also need client libraries: sudo apt install libpq-dev
PostgreSQL service usually starts automatically after installation.
-
For NixOS:
Add this to you system configuration:
config.services.postgresql = { extensions = ps: with ps; [ postgis pg_repack ]; enable = true; package = pkgs.postgresql_15; };
-
For macOS (using Homebrew):
If you don't have Homebrew, install it first from brew.sh.
brew install postgresql@15 # Or your preferred supported version, e.g., postgresql@16 brew install postgis # To have launchd start postgresql now and restart at login: brew services start postgresql@15 # Or, if you don't want/need a background service, you can manage it manually: # pg_ctl -D /usr/local/var/postgres start # (path might vary based on version)
Note: Homebrew might install a specific version (e.g.,
postgresql@15). Ensure yourPATHis updated as per Homebrew's instructions if you install a versioned formula, or link it.
2. Initial Postgres User and Database Setup:
Access psql as a PostgreSQL administrative user.
- On Linux:
sudo -u postgres psql
- On macOS:
Depending on your installation (especially with Homebrew), you might be able to run
psql postgresdirectly. If not, try:psql -U postgres -d template1 # Or your macOS username if you initialized the cluster as such
Now, within the psql prompt, create the klimatkalendern user and klimatkalendern database:
CREATE USER klimatkalendern WITH PASSWORD 'klimatkalendern';
CREATE DATABASE klimatkalendern OWNER klimatkalendern;
-- Connect to the new database to enable extensions within it
\c klimatkalendern;
-- Enable necessary extensions
CREATE EXTENSION IF NOT EXISTS postgis;
CREATE EXTENSION IF NOT EXISTS unaccent;
CREATE EXTENSION IF NOT EXISTS pg_trgm;
-- You can verify extensions with \dx
-- Exit psql
\q3. Setup database
You have two options:
- If you are starting from a clean slate, migrate database and add an admin user:
mix ecto.migrate
mix mobilizon.users.new john.doe@localhost.com --admin
-
If you're using an existing database dump (e.g. dbdump.sql)
- If you have existing data in the DB you need to clear it (see Reset Database section)
- import the dump into klimatkalendern and migrate.
psql -h localhost -U klimatkalendern -d klimatkalendern < path/to/your/downloaded/dbdump.sql mix ecto.migrateMake sure to replace path/to/your/downloaded/dbdump.sql with the actual path to the dump file you downloaded.
Download user-uploaded media files that match the database dump. Unzip this archive into an
./uploadsdirectory at the root of the cloned project.
4. Verify Database Setup:
Connect to the database as the mobilizon user and check that tables exist:
psql -h localhost -U klimatkalendern -d klimatkalendernInside psql, run:
\dtYou should see a list of tables. Exit with \q.
The database is now installed and configured.
Ensure you are inside the Nix development shell (nix develop or via direnv).
Install Elixir Dependencies (again):
mix deps.getIf prompted to install rebar3, answer y (yes).
Compile the Application:
According to upstream documentation, some commands are run with MIX_ENV=prod
the reason for this is unkown, we just do it because they do it.
MIX_ENV=prod mix compilepnpm install
pnpm run build
MIX_ENV=prod mix phx.digestRun the Phoenix Server:
mix phx.serverKlimatkalendern should now be available at http://localhost:4000.
Check upstream documentation for more info: https://docs.mobilizon.org/4.%20Contribute/development/
If you encounter issues, want to apply a fresh database dump, or need to start with a clean slate, you can reset your environment.
Warning: This process will delete your local klimatkalendern database, compiled code, and local dependencies.
Stop the Phoenix Server:
If mix phx.server is running, stop it (usually Ctrl+C twice in the terminal).
Clean Project Artifacts:
Ensure you are in the project's root directory.
# Clean Elixir build artifacts and compiled dependencies
mix clean
mix deps.clean --all
# Clean frontend dependencies and build artifacts
rm config/runtime.exs
rm -rf node_modules/
rm -rf priv/static/assetsReset Database:
Connect to psql as a PostgreSQL superuser (e.g., postgres on Linux, or your admin user on macOS):
Linux:
sudo -u postgres psqlmacOS:
psql -U postgres -d template1 (or similar, see setup)Then execute the following SQL commands:
-- Terminate any active connections to klimatkalendern before dropping
SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'klimatkalendern';
DROP DATABASE IF EXISTS klimatkalendern;
DROP USER IF EXISTS klimatkalendern;Exit psql (type \q and press Enter).
Nix Environment Refresh:
If you are using nix develop directly, exit the shell and re-enter it.
If using direnv, you can run direnv reload or touch flake.nix.
in the project directory to force a refresh of the environment.
Your environment is now reset and you can follow the setup guide from step 2 under Postgresql ("Initial Postgres User and Database setup").
We strive to keep up to date with the upstream repo. In order to ingest upstream changes, we follow the following procedure:
- Create a branch in our repo matching the release we want to ingest in upstream.
- Merge our
devinto that branch, resolving any merge conflicts. - Verify that the branch seems to work locally.
- Open a PR from that branch into
devand allow another maintainer to review the changes. Use a merge commit as a merging strategy. The effect in the history should be one commit on top ofdevwith the message "Merge Mobilizon vXX.XX" which has two parents - the previous dev tip, and the merge commit that was made on the upstream branch. - After acceptance, as usual deploy from dev, see that it seems to work, and then make a deployment into
main.
To show temporary announcements, there is code for it in "src/components/NavBar.vue", see the commented out code.