|
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 |
2 | 2 | # for the SyTest (https://github.com/matrix-org/sytest) and Complement |
3 | 3 | # (https://github.com/matrix-org/complement) Matrix homeserver test suites are also |
4 | 4 | # installed automatically. |
5 | 5 | # |
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 |
9 | 9 | # containers. Please refer to https://nixos.org/download for details. |
10 | 10 | # |
11 | 11 | # You must also enable support for flakes in Nix. See the following for how to |
12 | 12 | # do so permanently: https://nixos.wiki/wiki/Flakes#Enable_flakes |
13 | 13 | # |
| 14 | +# Be warned: you'll need over 3.75 GB of free space to download all the dependencies. |
| 15 | +# |
14 | 16 | # Usage: |
15 | 17 | # |
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 |
17 | 19 | # `nix develop --impure`. The `--impure` is necessary in order to store state |
18 | 20 | # locally from "services", such as PostgreSQL and Redis. |
19 | 21 | # |
20 | 22 | # You should now be dropped into a new shell with all programs and dependencies |
21 | 23 | # availabile to you! |
22 | 24 | # |
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 |
24 | 26 | # running: `devenv up`. To stop them, use Ctrl-C. |
25 | 27 | # |
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 | | -# |
33 | 28 | # All state (the venv, postgres and redis data and config) are stored in |
34 | 29 | # .devenv/state. Deleting a file from here and then re-entering the shell |
35 | 30 | # will recreate these files from scratch. |
|
66 | 61 | let |
67 | 62 | pkgs = nixpkgs.legacyPackages.${system}; |
68 | 63 | 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 |
70 | 65 | # developer environments. See https://devenv.sh/reference/options/ for a list |
71 | 66 | # of all possible options. |
72 | 67 | default = devenv.lib.mkShell { |
|
153 | 148 | # Redis is needed in order to run Synapse in worker mode. |
154 | 149 | services.redis.enable = true; |
155 | 150 |
|
| 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 | + |
156 | 179 | # Define the perl modules we require to run SyTest. |
157 | 180 | # |
158 | 181 | # This list was compiled by cross-referencing https://metacpan.org/ |
159 | 182 | # 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. |
161 | 184 | # |
162 | 185 | # This was done until `./install-deps.pl --dryrun` produced no output. |
163 | 186 | env.PERL5LIB = "${with pkgs.perl536Packages; makePerlPath [ |
|
0 commit comments