summary refs log tree commit diff
path: root/devenv.nix
blob: 8874df3a941aa253f3fd080aac9e1d30ac30a50e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
{ inputs, pkgs, ... }:

{
  # Configure packages to install.
  # Search for package names at https://search.nixos.org/packages?channel=unstable
  packages = with pkgs; [
    # Native dependencies for running Synapse.
    icu
    libffi
    libjpeg
    libpqxx
    libwebp
    libxml2
    libxslt
    sqlite

    # Native dependencies for unit tests (SyTest also requires OpenSSL).
    openssl

    # Native dependencies for running Complement.
    olm

    # Development tools.
    poetry
  ];

  # Activate (and create if necessary) a poetry virtualenv on startup.
  enterShell = ''
    . "$(dirname $(poetry run which python))/activate"
  '';

  # Install dependencies for the additional programming languages
  # involved with Synapse development. Python is already available
  # from poetry's virtual environment.
  #
  # * Rust is used for developing and running Synapse.
  # * Golang is needed to run the Complement test suite.
  # * Perl is needed to run the SyTest test suite.
  languages.go.enable = true;
  languages.rust.enable = true;
  languages.rust.version = "latest";
  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
  # Syanpse to store data in.
  services.postgres.initdbArgs = ["--locale=C" "--encoding=UTF8"];
  services.postgres.initialDatabases = [
    { name = "synapse"; }
  ];

  # Redis is needed in order to run Synapse in worker mode.
  services.redis.enable = true;

  # We wrap `poetry` with a bash script that disables the download
  # of binary wheels for certain packages if the user is running
  # NixOS. 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.
  scripts.poetry.exec = ''
  if [ -z "$__NIXOS_SET_ENVIRONMENT_DONE" ]; then
    # We are running on NixOS.
    #
    # Prevent poetry from downloading known problematic,
    # dynamically-linked binaries for python dependencies.
    POETRY_INSTALLER_NO_BINARY=ruff ${pkgs.poetry}/bin/poetry $@
  else
    ${pkgs.poetry}/bin/poetry $@
  fi
  '';

  # 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
  ]}";

}