From ae93158a1390e859e17a749ebdf63b5faba3e8dd Mon Sep 17 00:00:00 2001 From: axel simon Date: Wed, 17 May 2023 14:58:56 +0100 Subject: [PATCH 1/5] Start synapse with 'devenv up' Also, add space warning: takes +3.75GB Thanks to @anoadragon453 for helping out Signed-off-by: axel simon --- changelog.d/15613.doc | 1 + changelog.d/15613.feature | 1 + flake.nix | 40 ++++++++++++++++++++++++++++++++------- 3 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 changelog.d/15613.doc create mode 100644 changelog.d/15613.feature diff --git a/changelog.d/15613.doc b/changelog.d/15613.doc new file mode 100644 index 000000000000..15cd983ace45 --- /dev/null +++ b/changelog.d/15613.doc @@ -0,0 +1 @@ +Flake.nix: warn users that at least 3.75GB of space is needed. diff --git a/changelog.d/15613.feature b/changelog.d/15613.feature new file mode 100644 index 000000000000..11924da602cb --- /dev/null +++ b/changelog.d/15613.feature @@ -0,0 +1 @@ +Flake.nix: `devenv up` now automatically starts synapse, configured to use redis and postgresql. diff --git a/flake.nix b/flake.nix index 7351571e61de..0df7f43f2c9b 100644 --- a/flake.nix +++ b/flake.nix @@ -1,19 +1,21 @@ -# A nix flake that sets up a complete Synapse development environment. Dependencies +# A Nix flake that sets up a complete Synapse development environment. Dependencies # for the SyTest (https://github.com/matrix-org/sytest) and Complement # (https://github.com/matrix-org/complement) Matrix homeserver test suites are also # installed automatically. # -# You must have already installed nix (https://nixos.org) on your system to use this. -# nix can be installed on Linux or MacOS; NixOS is not required. Windows is not -# directly supported, but nix can be installed inside of WSL2 or even Docker +# You must have already installed Nix (https://nixos.org) on your system to use this. +# Nix can be installed on Linux or MacOS; NixOS is not required. Windows is not +# directly supported, but Nix can be installed inside of WSL2 or even Docker # containers. Please refer to https://nixos.org/download for details. # # You must also enable support for flakes in Nix. See the following for how to # do so permanently: https://nixos.wiki/wiki/Flakes#Enable_flakes # +# Be warned: you'll need over 3.75 GB of free space to download all the dependencies. +# # Usage: # -# With nix installed, navigate to the directory containing this flake and run +# With Nix installed, navigate to the directory containing this flake and run # `nix develop --impure`. The `--impure` is necessary in order to store state # locally from "services", such as PostgreSQL and Redis. # @@ -66,7 +68,7 @@ let pkgs = nixpkgs.legacyPackages.${system}; in { - # Everything is configured via devenv - a nix module for creating declarative + # Everything is configured via devenv - a Nix module for creating declarative # developer environments. See https://devenv.sh/reference/options/ for a list # of all possible options. default = devenv.lib.mkShell { @@ -153,11 +155,35 @@ # Redis is needed in order to run Synapse in worker mode. services.redis.enable = true; + # We are now ready to start Synapse. + + process.before = '' + python -m synapse.app.homeserver -c homeserver.yaml --generate-config --server-name=synapse.dev --report-stats=no + mkdir -p homeserver-config-overrides.d + cat > homeserver-config-overrides.d/database.yaml << EOF + ## Do not edit this file. This file is generated by flake.nix + database: + name: psycopg2 + args: + user: synapse_user + database: synapse + host: $PGHOST + cp_min: 5 + cp_max: 10 + EOF + cat > homeserver-config-overrides.d/redis.yaml << EOF + ## Do not edit this file. This file is generated by flake.nix + redis: + enabled: true + EOF + ''; + processes.synapse.exec = "poetry run python -m synapse.app.homeserver -c homeserver.yaml --config-directory homeserver-config-overrides.d"; + # Define the perl modules we require to run SyTest. # # This list was compiled by cross-referencing https://metacpan.org/ # with the modules defined in './cpanfile' and then finding the - # corresponding nix packages on https://search.nixos.org/packages. + # corresponding Nix packages on https://search.nixos.org/packages. # # This was done until `./install-deps.pl --dryrun` produced no output. env.PERL5LIB = "${with pkgs.perl536Packages; makePerlPath [ From 1952bd26a5297077a55a883c26bca3c9d618216b Mon Sep 17 00:00:00 2001 From: axel simon Date: Thu, 18 May 2023 12:18:54 +0100 Subject: [PATCH 2/5] Improve flake.nix inline comments Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> --- flake.nix | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 0df7f43f2c9b..4b6519094e66 100644 --- a/flake.nix +++ b/flake.nix @@ -155,8 +155,11 @@ # Redis is needed in order to run Synapse in worker mode. services.redis.enable = true; - # We are now ready to start Synapse. - + # Configure and start Synapse. Before starting Synapse, this shell code: + # * generates a default homeserver.yaml config file if one does not exist, and + # * ensures a directory containing two additional homeserver config files exists; + # one to configure using the development environment's PostgreSQL as the + # database backend and another for enabling Redis support. process.before = '' python -m synapse.app.homeserver -c homeserver.yaml --generate-config --server-name=synapse.dev --report-stats=no mkdir -p homeserver-config-overrides.d From ec28bbc095c29f006d73ffa6c8c77416e5033d83 Mon Sep 17 00:00:00 2001 From: axel simon Date: Thu, 18 May 2023 12:19:30 +0100 Subject: [PATCH 3/5] Improve flake.nix inline comments Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> --- flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/flake.nix b/flake.nix index 4b6519094e66..035b4a42055c 100644 --- a/flake.nix +++ b/flake.nix @@ -180,6 +180,7 @@ enabled: true EOF ''; + # Start synapse when `devenv up` is run. processes.synapse.exec = "poetry run python -m synapse.app.homeserver -c homeserver.yaml --config-directory homeserver-config-overrides.d"; # Define the perl modules we require to run SyTest. From 69960572e5e3a0c3214ccd80d82030d78b2ab589 Mon Sep 17 00:00:00 2001 From: axel simon Date: Thu, 18 May 2023 12:20:49 +0100 Subject: [PATCH 4/5] Update changelog.d/15613.doc Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> --- changelog.d/15613.doc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/15613.doc b/changelog.d/15613.doc index 15cd983ace45..94733facf001 100644 --- a/changelog.d/15613.doc +++ b/changelog.d/15613.doc @@ -1 +1 @@ -Flake.nix: warn users that at least 3.75GB of space is needed. +Warn users that at least 3.75GB of space is needed for the nix Synapse development environment. From dcd63eaa0e2084ea1bcee16d5c69c877818850d3 Mon Sep 17 00:00:00 2001 From: axel simon Date: Thu, 18 May 2023 12:28:17 +0100 Subject: [PATCH 5/5] Remove unneeded changelog fragment Signed-off-by: axel simon --- changelog.d/15613.feature | 1 - flake.nix | 9 +-------- 2 files changed, 1 insertion(+), 9 deletions(-) delete mode 100644 changelog.d/15613.feature diff --git a/changelog.d/15613.feature b/changelog.d/15613.feature deleted file mode 100644 index 11924da602cb..000000000000 --- a/changelog.d/15613.feature +++ /dev/null @@ -1 +0,0 @@ -Flake.nix: `devenv up` now automatically starts synapse, configured to use redis and postgresql. diff --git a/flake.nix b/flake.nix index 035b4a42055c..8d2bf779bd82 100644 --- a/flake.nix +++ b/flake.nix @@ -22,16 +22,9 @@ # You should now be dropped into a new shell with all programs and dependencies # availabile to you! # -# You can start up pre-configured, local PostgreSQL and Redis instances by +# You can start up pre-configured local Synapse, PostgreSQL and Redis instances by # running: `devenv up`. To stop them, use Ctrl-C. # -# A PostgreSQL database called 'synapse' will be set up for you, along with -# a PostgreSQL user named 'synapse_user'. -# The 'host' can be found by running `echo $PGHOST` with the development -# shell activated. Use these values to configure your Synapse to connect -# to the local PostgreSQL database. You do not need to specify a password. -# https://matrix-org.github.io/synapse/latest/postgres -# # All state (the venv, postgres and redis data and config) are stored in # .devenv/state. Deleting a file from here and then re-entering the shell # will recreate these files from scratch.