Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 4ec40b1

Browse files
flake.nix: start synapse automatically, add space usage warning (#15613)
Co-authored-by: Andrew Morgan <[email protected]>
1 parent 68dcd2c commit 4ec40b1

File tree

2 files changed

+39
-15
lines changed

2 files changed

+39
-15
lines changed

changelog.d/15613.doc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Warn users that at least 3.75GB of space is needed for the nix Synapse development environment.

flake.nix

+38-15
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,30 @@
1-
# A nix flake that sets up a complete Synapse development environment. Dependencies
1+
# A Nix flake that sets up a complete Synapse development environment. Dependencies
22
# for the SyTest (https://github.com/matrix-org/sytest) and Complement
33
# (https://github.com/matrix-org/complement) Matrix homeserver test suites are also
44
# installed automatically.
55
#
6-
# You must have already installed nix (https://nixos.org) on your system to use this.
7-
# nix can be installed on Linux or MacOS; NixOS is not required. Windows is not
8-
# directly supported, but nix can be installed inside of WSL2 or even Docker
6+
# You must have already installed Nix (https://nixos.org) on your system to use this.
7+
# Nix can be installed on Linux or MacOS; NixOS is not required. Windows is not
8+
# directly supported, but Nix can be installed inside of WSL2 or even Docker
99
# containers. Please refer to https://nixos.org/download for details.
1010
#
1111
# You must also enable support for flakes in Nix. See the following for how to
1212
# do so permanently: https://nixos.wiki/wiki/Flakes#Enable_flakes
1313
#
14+
# Be warned: you'll need over 3.75 GB of free space to download all the dependencies.
15+
#
1416
# Usage:
1517
#
16-
# With nix installed, navigate to the directory containing this flake and run
18+
# With Nix installed, navigate to the directory containing this flake and run
1719
# `nix develop --impure`. The `--impure` is necessary in order to store state
1820
# locally from "services", such as PostgreSQL and Redis.
1921
#
2022
# You should now be dropped into a new shell with all programs and dependencies
2123
# availabile to you!
2224
#
23-
# You can start up pre-configured, local PostgreSQL and Redis instances by
25+
# You can start up pre-configured local Synapse, PostgreSQL and Redis instances by
2426
# running: `devenv up`. To stop them, use Ctrl-C.
2527
#
26-
# A PostgreSQL database called 'synapse' will be set up for you, along with
27-
# a PostgreSQL user named 'synapse_user'.
28-
# The 'host' can be found by running `echo $PGHOST` with the development
29-
# shell activated. Use these values to configure your Synapse to connect
30-
# to the local PostgreSQL database. You do not need to specify a password.
31-
# https://matrix-org.github.io/synapse/latest/postgres
32-
#
3328
# All state (the venv, postgres and redis data and config) are stored in
3429
# .devenv/state. Deleting a file from here and then re-entering the shell
3530
# will recreate these files from scratch.
@@ -66,7 +61,7 @@
6661
let
6762
pkgs = nixpkgs.legacyPackages.${system};
6863
in {
69-
# Everything is configured via devenv - a nix module for creating declarative
64+
# Everything is configured via devenv - a Nix module for creating declarative
7065
# developer environments. See https://devenv.sh/reference/options/ for a list
7166
# of all possible options.
7267
default = devenv.lib.mkShell {
@@ -153,11 +148,39 @@
153148
# Redis is needed in order to run Synapse in worker mode.
154149
services.redis.enable = true;
155150

151+
# Configure and start Synapse. Before starting Synapse, this shell code:
152+
# * generates a default homeserver.yaml config file if one does not exist, and
153+
# * ensures a directory containing two additional homeserver config files exists;
154+
# one to configure using the development environment's PostgreSQL as the
155+
# database backend and another for enabling Redis support.
156+
process.before = ''
157+
python -m synapse.app.homeserver -c homeserver.yaml --generate-config --server-name=synapse.dev --report-stats=no
158+
mkdir -p homeserver-config-overrides.d
159+
cat > homeserver-config-overrides.d/database.yaml << EOF
160+
## Do not edit this file. This file is generated by flake.nix
161+
database:
162+
name: psycopg2
163+
args:
164+
user: synapse_user
165+
database: synapse
166+
host: $PGHOST
167+
cp_min: 5
168+
cp_max: 10
169+
EOF
170+
cat > homeserver-config-overrides.d/redis.yaml << EOF
171+
## Do not edit this file. This file is generated by flake.nix
172+
redis:
173+
enabled: true
174+
EOF
175+
'';
176+
# Start synapse when `devenv up` is run.
177+
processes.synapse.exec = "poetry run python -m synapse.app.homeserver -c homeserver.yaml --config-directory homeserver-config-overrides.d";
178+
156179
# Define the perl modules we require to run SyTest.
157180
#
158181
# This list was compiled by cross-referencing https://metacpan.org/
159182
# with the modules defined in './cpanfile' and then finding the
160-
# corresponding nix packages on https://search.nixos.org/packages.
183+
# corresponding Nix packages on https://search.nixos.org/packages.
161184
#
162185
# This was done until `./install-deps.pl --dryrun` produced no output.
163186
env.PERL5LIB = "${with pkgs.perl536Packages; makePerlPath [

0 commit comments

Comments
 (0)