1{
2 lib,
3 fetchFromGitHub,
4 rustPlatform,
5 cacert,
6 buildPythonPackage,
7 uvloop,
8 click,
9 setproctitle,
10 watchfiles,
11 versionCheckHook,
12 pytestCheckHook,
13 pytest-asyncio,
14 websockets,
15 httpx,
16 sniffio,
17 nix-update-script,
18}:
19
20buildPythonPackage rec {
21 pname = "granian";
22 version = "2.5.4";
23 pyproject = true;
24
25 src = fetchFromGitHub {
26 owner = "emmett-framework";
27 repo = "granian";
28 tag = "v${version}";
29 hash = "sha256-6T4ge9QrLxpkgtJvNmgUlHaxFK3KyQLJo12rjs80J3M=";
30 };
31
32 # Granian forces a custom allocator for all the things it runs,
33 # which breaks some libraries in funny ways. Make it not do that,
34 # and allow the final application to make the allocator decision
35 # via LD_PRELOAD or similar.
36 patches = [
37 ./no-alloc.patch
38 ];
39
40 cargoDeps = rustPlatform.fetchCargoVendor {
41 inherit pname version src;
42 hash = "sha256-iY0vh+Y0wU1/wJVXb2GDG8vb5ovrFD+4tXKODEA35Kc=";
43 };
44
45 nativeBuildInputs = with rustPlatform; [
46 cargoSetupHook
47 maturinBuildHook
48 ];
49
50 dependencies = [
51 click
52 ];
53
54 optional-dependencies = {
55 pname = [ setproctitle ];
56 reload = [ watchfiles ];
57 # rloop = [ rloop ]; # not packaged
58 uvloop = [ uvloop ];
59 };
60
61 nativeCheckInputs = [
62 versionCheckHook
63 pytestCheckHook
64 pytest-asyncio
65 websockets
66 httpx
67 sniffio
68 ];
69
70 preCheck = ''
71 # collides with the one installed in $out
72 rm -rf granian/
73 '';
74
75 # needed for checks
76 env.SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt";
77
78 __darwinAllowLocalNetworking = true;
79
80 enabledTestPaths = [ "tests/" ];
81
82 pythonImportsCheck = [ "granian" ];
83
84 versionCheckProgramArg = "--version";
85
86 passthru.updateScript = nix-update-script { };
87
88 meta = {
89 description = "Rust HTTP server for Python ASGI/WSGI/RSGI applications";
90 homepage = "https://github.com/emmett-framework/granian";
91 changelog = "https://github.com/emmett-framework/granian/releases/tag/v${version}";
92 license = lib.licenses.bsd3;
93 mainProgram = "granian";
94 maintainers = with lib.maintainers; [
95 lucastso10
96 pbsds
97 ];
98 platforms = lib.platforms.unix;
99 };
100}