NixOS Virtualbox Dev VM
You can use the official NixOS VirtualBox appliance if you want to run the project on our preferred production system NixOS.
This will guide you from downloading the appliance to a running application.
Note
You need VirtualBox installed on your system.
Note
If you want to run the application elsewhere, please look at Development Quick Start
VM Preparation
The following code snippets are written for ekklesia-portal but also work for ekklesia-voting when you change the project name.
Get the NixOS 22.11 VirtualBox appliance and follow the instructions there to import and start the VM. Enable clipboard integration in the VirtualBox menu bar with Devices -> Shared Clipboard -> Host to Guest so you can copy-paste longer commands from here.
In the VM, open konsole (press Alt-F1 and type konsole) and run the following commands as the demo user.
Add the edemocracy binary cache:
# password for sudo is `demo` nix-shell -p cachix --run "sudo cachix use edemocracy" # ignore the instructions shown by cachix, we do that later.
Edit
/etc/nixos/configuration.nix
(usingsudo nano /etc/nixos/configuration.nix
, for example) and change theimports
line to:# no commas between list items in Nix! imports = [ <nixpkgs/nixos/modules/installer/virtualbox-demo.nix> ./ekklesia_dev.nix ];
Fetch our recommended NixOS configuration with curl and put it in
/etc/nixos
(you can alsodownload it here
):curl -O https://raw.githubusercontent.com/edemocracy/ekklesia/master/docs/development/ekklesia_dev.nix sudo mv ekklesia_dev.nix /etc/nixos
Rebuild the NixOS system to activate the new configuration and run zsh as new shell:
sudo nixos-rebuild switch zsh
Tell direnv where nix-direnv is located:
echo "source /run/current-system/sw/share/nix-direnv/direnvrc" > ~/.direnvrc
Setting up the Project
Clone the repository and change to the checked out directory:
git clone https://github.com/edemocracy/ekklesia-portal cd ekklesia-portal
Tell
direnv
to usenix-direnv
whenever you enter the directory.nix-direnv
starts building immediately which may take a while:cp envrc.example .envrc direnv allow # direnv runs nix build now
You can run
direnv allow
again to activate changes to the .envrc file or get an up-to-date shell when direnv couldn’t run automatically.Compile translations and CSS (look at dodo.py to see what this does):
doit
Create a config file named
config.yml
using the config template fromsrc/ekklesia_portal/config.example.yml
. Underdatabase
, you have to changeuri
. Underapp
, changeforce_ssl
to false andinsecure_development_mode
to true. The config file should look like this:database: uri: "postgresql+psycopg2:///ekklesia_portal?host=/run/postgresql" app: instance_name: my_ekklesia_portal insecure_development_mode: true login_visible: true force_ssl: false browser_session: secret_key: dev cookie_secure: false permanent_lifetime: 999999
Initialize the dev database:
create_dev_db
This command populates the
ekklesia_portal
database.Run the development server (look at
flake.nix
to see what this does):run_dev
You can use a browser, for example Firefox which is pre-installed on the VM to go to the application running at
http://localhost:8080
. Log in astestuser
, ortestadmin
for a privileged admin user.To compile changes to stylesheets and translations automatically, run in a second shell tab/window:
doit_auto
Setting up Tests
To set the test database connection URL {file}, open
.envrc
in an editor and uncomment the line withEKKLESIA_PORTAL_TEST_DB_URL
(remove the#
) . The line in the file should look like this now:EKKLESIA_PORTAL_TEST_DB_URL="postgresql+psycopg2:///test_ekklesia_portal?host=/run/postgresql"
Run
direnv allow
to activate changes to.envrc
.Set up test data:
create_test_db
This command populates the
test_ekklesia_portal
database.Run all tests:
pytest