From a74b82734ab99f5291106d908f5928aee545e7c8 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Fri, 20 Oct 2023 17:18:48 +0100 Subject: [PATCH] Migrate Synapse flake to element-hq/nix-flakes --- flake.lock | 342 ++++++++++++++++++++++++++++++++++++++++++----------- flake.nix | 230 +++-------------------------------- 2 files changed, 284 insertions(+), 288 deletions(-) diff --git a/flake.lock b/flake.lock index 9b360fa33e..bb83176d0b 100644 --- a/flake.lock +++ b/flake.lock @@ -1,24 +1,112 @@ { "nodes": { - "devenv": { + "cachix": { "inputs": { - "flake-compat": "flake-compat", - "nix": "nix", - "nixpkgs": "nixpkgs", - "pre-commit-hooks": "pre-commit-hooks" + "devenv": "devenv_2", + "flake-compat": [ + "element-nix-flakes", + "devenv", + "flake-compat" + ], + "nixpkgs": [ + "element-nix-flakes", + "devenv", + "nixpkgs" + ], + "pre-commit-hooks": [ + "element-nix-flakes", + "devenv", + "pre-commit-hooks" + ] }, "locked": { - "lastModified": 1688058187, - "narHash": "sha256-ipDcc7qrucpJ0+0eYNlwnE+ISTcq4m03qW+CWUshRXI=", + "lastModified": 1712055811, + "narHash": "sha256-7FcfMm5A/f02yyzuavJe06zLa9hcMHsagE28ADcmQvk=", "owner": "cachix", - "repo": "devenv", - "rev": "c8778e3dc30eb9043e218aaa3861d42d4992de77", + "repo": "cachix", + "rev": "02e38da89851ec7fec3356a5c04bc8349cae0e30", "type": "github" }, "original": { "owner": "cachix", - "ref": "v0.6.3", + "repo": "cachix", + "type": "github" + } + }, + "devenv": { + "inputs": { + "cachix": "cachix", + "flake-compat": "flake-compat_2", + "nix": "nix_2", + "nixpkgs": "nixpkgs_2", + "pre-commit-hooks": "pre-commit-hooks" + }, + "locked": { + "lastModified": 1718265154, + "narHash": "sha256-eTbBvYwGlKExMSTyHQya6+6kdx1rtva/aVfyAZu2NUU=", + "owner": "cachix", "repo": "devenv", + "rev": "1983f635c29dc68bb0d29b3a7e227579a1d98788", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "v1.0.7", + "repo": "devenv", + "type": "github" + } + }, + "devenv_2": { + "inputs": { + "flake-compat": [ + "element-nix-flakes", + "devenv", + "cachix", + "flake-compat" + ], + "nix": "nix", + "nixpkgs": "nixpkgs", + "poetry2nix": "poetry2nix", + "pre-commit-hooks": [ + "element-nix-flakes", + "devenv", + "cachix", + "pre-commit-hooks" + ] + }, + "locked": { + "lastModified": 1708704632, + "narHash": "sha256-w+dOIW60FKMaHI1q5714CSibk99JfYxm0CzTinYWr+Q=", + "owner": "cachix", + "repo": "devenv", + "rev": "2ee4450b0f4b95a1b90f2eb5ffea98b90e48c196", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "python-rewrite", + "repo": "devenv", + "type": "github" + } + }, + "element-nix-flakes": { + "inputs": { + "devenv": "devenv", + "nixpkgs": "nixpkgs_3", + "rust-overlay": "rust-overlay", + "systems": "systems_3" + }, + "locked": { + "lastModified": 1719311692, + "narHash": "sha256-WYtaML+xsn5r+de6cgi41rXa+6OP9RFLHd4FFxJQCvg=", + "owner": "element-hq", + "repo": "nix-flakes", + "rev": "3d1e3ee99be86b5535c371d13b94a9af02c0ce06", + "type": "github" + }, + "original": { + "owner": "element-hq", + "repo": "nix-flakes", "type": "github" } }, @@ -38,16 +126,32 @@ "type": "github" } }, + "flake-compat_2": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-utils": { "inputs": { "systems": "systems" }, "locked": { - "lastModified": 1685518550, - "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", + "lastModified": 1689068808, + "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", "owner": "numtide", "repo": "flake-utils", - "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", + "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", "type": "github" }, "original": { @@ -61,11 +165,11 @@ "systems": "systems_2" }, "locked": { - "lastModified": 1681202837, - "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "cfacdce06f30d2b68473a46042957675eebb3401", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", "type": "github" }, "original": { @@ -77,17 +181,18 @@ "gitignore": { "inputs": { "nixpkgs": [ + "element-nix-flakes", "devenv", "pre-commit-hooks", "nixpkgs" ] }, "locked": { - "lastModified": 1660459072, - "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", "owner": "hercules-ci", "repo": "gitignore.nix", - "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", "type": "github" }, "original": { @@ -96,53 +201,94 @@ "type": "github" } }, - "lowdown-src": { - "flake": false, - "locked": { - "lastModified": 1633514407, - "narHash": "sha256-Dw32tiMjdK9t3ETl5fzGrutQTzh2rufgZV4A/BbxuD4=", - "owner": "kristapsdz", - "repo": "lowdown", - "rev": "d2c2b44ff6c27b936ec27358a2653caaef8f73b8", - "type": "github" - }, - "original": { - "owner": "kristapsdz", - "repo": "lowdown", - "type": "github" - } - }, "nix": { "inputs": { - "lowdown-src": "lowdown-src", + "flake-compat": "flake-compat", "nixpkgs": [ + "element-nix-flakes", + "devenv", + "cachix", "devenv", "nixpkgs" ], "nixpkgs-regression": "nixpkgs-regression" }, "locked": { - "lastModified": 1676545802, - "narHash": "sha256-EK4rZ+Hd5hsvXnzSzk2ikhStJnD63odF7SzsQ8CuSPU=", + "lastModified": 1712911606, + "narHash": "sha256-BGvBhepCufsjcUkXnEEXhEVjwdJAwPglCC2+bInc794=", "owner": "domenkozar", "repo": "nix", - "rev": "7c91803598ffbcfe4a55c44ac6d49b2cf07a527f", + "rev": "b24a9318ea3f3600c1e24b4a00691ee912d4de12", "type": "github" }, "original": { "owner": "domenkozar", - "ref": "relaxed-flakes", + "ref": "devenv-2.21", + "repo": "nix", + "type": "github" + } + }, + "nix-github-actions": { + "inputs": { + "nixpkgs": [ + "element-nix-flakes", + "devenv", + "cachix", + "devenv", + "poetry2nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1688870561, + "narHash": "sha256-4UYkifnPEw1nAzqqPOTL2MvWtm3sNGw1UTYTalkTcGY=", + "owner": "nix-community", + "repo": "nix-github-actions", + "rev": "165b1650b753316aa7f1787f3005a8d2da0f5301", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nix-github-actions", + "type": "github" + } + }, + "nix_2": { + "inputs": { + "flake-compat": [ + "element-nix-flakes", + "devenv", + "flake-compat" + ], + "nixpkgs": [ + "element-nix-flakes", + "devenv", + "nixpkgs" + ], + "nixpkgs-regression": "nixpkgs-regression_2" + }, + "locked": { + "lastModified": 1712911606, + "narHash": "sha256-BGvBhepCufsjcUkXnEEXhEVjwdJAwPglCC2+bInc794=", + "owner": "domenkozar", + "repo": "nix", + "rev": "b24a9318ea3f3600c1e24b4a00691ee912d4de12", + "type": "github" + }, + "original": { + "owner": "domenkozar", + "ref": "devenv-2.21", "repo": "nix", "type": "github" } }, "nixpkgs": { "locked": { - "lastModified": 1678875422, - "narHash": "sha256-T3o6NcQPwXjxJMn2shz86Chch4ljXgZn746c2caGxd8=", + "lastModified": 1692808169, + "narHash": "sha256-x9Opq06rIiwdwGeK2Ykj69dNc2IvUH1fY55Wm7atwrE=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "126f49a01de5b7e35a43fd43f891ecf6d3a51459", + "rev": "9201b5ff357e781bf014d0330d18555695df7ba8", "type": "github" }, "original": { @@ -168,45 +314,73 @@ "type": "github" } }, - "nixpkgs-stable": { + "nixpkgs-regression_2": { "locked": { - "lastModified": 1685801374, - "narHash": "sha256-otaSUoFEMM+LjBI1XL/xGB5ao6IwnZOXc47qhIgJe8U=", + "lastModified": 1643052045, + "narHash": "sha256-uGJ0VXIhWKGXxkeNnq4TvV3CIOkUJ3PAoLZ3HMzNVMw=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "c37ca420157f4abc31e26f436c1145f8951ff373", + "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixos-23.05", + "repo": "nixpkgs", + "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1710695816, + "narHash": "sha256-3Eh7fhEID17pv9ZxrPwCLfqXnYP006RKzSs0JptsN84=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "614b4613980a522ba49f0d194531beddbb7220d3", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.11", "repo": "nixpkgs", "type": "github" } }, "nixpkgs_2": { "locked": { - "lastModified": 1690535733, - "narHash": "sha256-WgjUPscQOw3cB8yySDGlyzo6cZNihnRzUwE9kadv/5I=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "8cacc05fbfffeaab910e8c2c9e2a7c6b32ce881a", + "lastModified": 1713361204, + "narHash": "sha256-TA6EDunWTkc5FvDCqU3W2T3SFn0gRZqh6D/hJnM02MM=", + "owner": "cachix", + "repo": "devenv-nixpkgs", + "rev": "285676e87ad9f0ca23d8714a6ab61e7e027020c6", "type": "github" }, "original": { - "owner": "NixOS", - "ref": "master", - "repo": "nixpkgs", + "owner": "cachix", + "ref": "rolling", + "repo": "devenv-nixpkgs", "type": "github" } }, "nixpkgs_3": { "locked": { - "lastModified": 1681358109, - "narHash": "sha256-eKyxW4OohHQx9Urxi7TQlFBTDWII+F+x2hklDOQPB50=", + "lastModified": 0, + "narHash": "sha256-CyyxvOwFf12I91PBWz43iGT1kjsf5oi6ax7CrvaMyAo=", + "path": "/nix/store/yqy82fn77fy3rv7lpwa9m11w3a2nnqg5-source", + "type": "path" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_4": { + "locked": { + "lastModified": 1718428119, + "narHash": "sha256-WdWDpNaq6u1IPtxtYHHWpl5BmabtpmLnMAx0RdJ/vo8=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "96ba1c52e54e74c3197f4d43026b3f3d92e83ff9", + "rev": "e6cea36f83499eb4e9cd184c8a8e823296b50ad5", "type": "github" }, "original": { @@ -216,26 +390,54 @@ "type": "github" } }, + "poetry2nix": { + "inputs": { + "flake-utils": "flake-utils", + "nix-github-actions": "nix-github-actions", + "nixpkgs": [ + "element-nix-flakes", + "devenv", + "cachix", + "devenv", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1692876271, + "narHash": "sha256-IXfZEkI0Mal5y1jr6IRWMqK8GW2/f28xJenZIPQqkY0=", + "owner": "nix-community", + "repo": "poetry2nix", + "rev": "d5006be9c2c2417dafb2e2e5034d83fabd207ee3", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "poetry2nix", + "type": "github" + } + }, "pre-commit-hooks": { "inputs": { "flake-compat": [ + "element-nix-flakes", "devenv", "flake-compat" ], - "flake-utils": "flake-utils", + "flake-utils": "flake-utils_2", "gitignore": "gitignore", "nixpkgs": [ + "element-nix-flakes", "devenv", "nixpkgs" ], "nixpkgs-stable": "nixpkgs-stable" }, "locked": { - "lastModified": 1688056373, - "narHash": "sha256-2+SDlNRTKsgo3LBRiMUcoEUb6sDViRNQhzJquZ4koOI=", + "lastModified": 1713775815, + "narHash": "sha256-Wu9cdYTnGQQwtT20QQMg7jzkANKQjwBD9iccfGKkfls=", "owner": "cachix", "repo": "pre-commit-hooks.nix", - "rev": "5843cf069272d92b60c3ed9e55b7a8989c01d4c7", + "rev": "2ac4dcbf55ed43f3be0bae15e181f08a57af24a4", "type": "github" }, "original": { @@ -246,23 +448,19 @@ }, "root": { "inputs": { - "devenv": "devenv", - "nixpkgs": "nixpkgs_2", - "rust-overlay": "rust-overlay", - "systems": "systems_3" + "element-nix-flakes": "element-nix-flakes" } }, "rust-overlay": { "inputs": { - "flake-utils": "flake-utils_2", - "nixpkgs": "nixpkgs_3" + "nixpkgs": "nixpkgs_4" }, "locked": { - "lastModified": 1693966243, - "narHash": "sha256-a2CA1aMIPE67JWSVIGoGtD3EGlFdK9+OlJQs0FOWCKY=", + "lastModified": 1719281921, + "narHash": "sha256-LIBMfhM9pMOlEvBI757GOK5l0R58SRi6YpwfYMbf4yc=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "a8b4bb4cbb744baaabc3e69099f352f99164e2c1", + "rev": "b6032d3a404d8a52ecfc8571ff0c26dfbe221d07", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 31f2832939..a8d2fb05d6 100644 --- a/flake.nix +++ b/flake.nix @@ -39,224 +39,22 @@ { inputs = { - # Use the master/unstable branch of nixpkgs. Used to fetch the latest - # available versions of packages. - nixpkgs.url = "github:NixOS/nixpkgs/master"; - # Output a development shell for x86_64/aarch64 Linux/Darwin (MacOS). - systems.url = "github:nix-systems/default"; - # A development environment manager built on Nix. See https://devenv.sh. - devenv.url = "github:cachix/devenv/v0.6.3"; - # Rust toolchain. - rust-overlay.url = "github:oxalica/rust-overlay"; + # A repository of nix development environment flakes. + element-nix-flakes.url = "github:element-hq/nix-flakes"; }; - outputs = { self, nixpkgs, devenv, systems, rust-overlay, ... } @ inputs: - let - forEachSystem = nixpkgs.lib.genAttrs (import systems); - in { - devShells = forEachSystem (system: - let - overlays = [ (import rust-overlay) ]; - pkgs = import nixpkgs { - inherit system overlays; - }; - in { - # 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 { - inherit inputs pkgs; - modules = [ - { - # Make use of the Starship command prompt when this development environment - # is manually activated (via `nix develop --impure`). - # See https://starship.rs/ for details on the prompt itself. - starship.enable = true; + outputs = { self, element-nix-flakes, ... }: + { + # Use the `composeShell` function provided by nix-flakes + # and specify the projects we'd like dependencies for. + devShells = element-nix-flakes.outputs.composeShell [ + "complement" + "synapse" + "sytest" + ]; - # Configure packages to install. - # Search for package names at https://search.nixos.org/packages?channel=unstable - packages = with pkgs; [ - # The rust toolchain and related tools. - # This will install the "default" profile of rust components. - # https://rust-lang.github.io/rustup/concepts/profiles.html - # - # NOTE: We currently need to set the Rust version unnecessarily high - # in order to work around https://github.com/matrix-org/synapse/issues/15939 - (rust-bin.stable."1.71.1".default.override { - # Additionally install the "rust-src" extension to allow diving into the - # Rust source code in an IDE (rust-analyzer will also make use of it). - extensions = [ "rust-src" ]; - }) - # The rust-analyzer language server implementation. - rust-analyzer - - # GCC includes a linker; needed for building `ruff` - gcc - # Needed for building `ruff` - gnumake - - # Native dependencies for running Synapse. - icu - libffi - libjpeg - libpqxx - libwebp - libxml2 - libxslt - sqlite - - # Native dependencies for unit tests (SyTest also requires OpenSSL). - openssl - xmlsec - - # Native dependencies for running Complement. - olm - - # For building the Synapse documentation website. - mdbook - - # For releasing Synapse - debian-devscripts # (`dch` for manipulating the Debian changelog) - libnotify # (the release script uses `notify-send` to tell you when CI jobs are done) - ]; - - # Install Python and manage a virtualenv with Poetry. - languages.python.enable = true; - languages.python.poetry.enable = true; - # Automatically activate the poetry virtualenv upon entering the shell. - languages.python.poetry.activate.enable = true; - # Install all extra Python dependencies; this is needed to run the unit - # tests and utilitise all Synapse features. - languages.python.poetry.install.arguments = ["--extras all"]; - # Install the 'matrix-synapse' package from the local checkout. - languages.python.poetry.install.installRootPackage = true; - - # This is a work-around for NixOS systems. NixOS is special in - # that you can have multiple versions of packages installed at - # once, including your libc linker! - # - # Some binaries built for Linux expect those to be in a certain - # filepath, but that is not the case on NixOS. In that case, we - # force compiling those binaries locally instead. - env.POETRY_INSTALLER_NO_BINARY = "ruff"; - - # Install dependencies for the additional programming languages - # involved with Synapse development. - # - # * Golang is needed to run the Complement test suite. - # * Perl is needed to run the SyTest test suite. - # * Rust is used for developing and running Synapse. - # It is installed manually with `packages` above. - languages.go.enable = true; - languages.perl.enable = true; - - # Postgres is needed to run Synapse with postgres support and - # to run certain unit tests that require postgres. - services.postgres.enable = true; - - # On the first invocation of `devenv up`, create a database for - # Synapse to store data in. - services.postgres.initdbArgs = ["--locale=C" "--encoding=UTF8"]; - services.postgres.initialDatabases = [ - { name = "synapse"; } - ]; - # Create a postgres user called 'synapse_user' which has ownership - # over the 'synapse' database. - services.postgres.initialScript = '' - CREATE USER synapse_user; - ALTER DATABASE synapse OWNER TO synapse_user; - ''; - - # Redis is needed in order to run Synapse in worker mode. - services.redis.enable = true; - - # 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 - 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 - ''; - # Start synapse when `devenv up` is run. - processes.synapse.exec = "poetry run python -m synapse.app.homeserver -c homeserver.yaml -c 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. - # - # This was done until `./install-deps.pl --dryrun` produced no output. - env.PERL5LIB = "${with pkgs.perl536Packages; makePerlPath [ - DBI - ClassMethodModifiers - CryptEd25519 - DataDump - DBDPg - DigestHMAC - DigestSHA1 - EmailAddressXS - EmailMIME - EmailSimple # required by Email::Mime - EmailMessageID # required by Email::Mime - EmailMIMEContentType # required by Email::Mime - TextUnidecode # required by Email::Mime - ModuleRuntime # required by Email::Mime - EmailMIMEEncodings # required by Email::Mime - FilePath - FileSlurper - Future - GetoptLong - HTTPMessage - IOAsync - IOAsyncSSL - IOSocketSSL - NetSSLeay - JSON - ListUtilsBy - ScalarListUtils - ModulePluggable - NetAsyncHTTP - MetricsAny # required by Net::Async::HTTP - NetAsyncHTTPServer - StructDumb - URI - YAMLLibYAML - ]}"; - - # Clear the LD_LIBRARY_PATH environment variable on shell init. - # - # By default, devenv will set LD_LIBRARY_PATH to point to .devenv/profile/lib. This causes - # issues when we include `gcc` as a dependency to build C libraries, as the version of glibc - # that the development environment's cc compiler uses may differ from that of the system. - # - # When LD_LIBRARY_PATH is set, system tools will attempt to use the development environment's - # libraries. Which, when built against a different glibc version lead, to "version 'GLIBC_X.YY' - # not found" errors. - enterShell = '' - unset LD_LIBRARY_PATH - ''; - } - ]; - }; - }); + # Use the `setupPackages` function provided by nix-flakes + # in order to make `devenv up` work. + packages = element-nix-flakes.outputs.setupPackages "synapse"; }; }