-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathflake.nix
124 lines (111 loc) · 4.02 KB
/
flake.nix
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
123
124
{
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
inputs.poetry2nix = {
url = "github:nix-community/poetry2nix";
inputs.nixpkgs.follows = "nixpkgs";
};
inputs.pre-commit-hooks = {
url = "github:cachix/pre-commit-hooks.nix";
};
outputs = { self, nixpkgs, flake-utils, poetry2nix, pre-commit-hooks, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
};
p2n = (poetry2nix.lib.mkPoetry2Nix { inherit pkgs; });
apibara-sdk = p2n.mkPoetryEnv {
python = pkgs.python310;
projectDir = ./.;
editablePackageSources = {
apibara = if builtins.getEnv "PROJECT_DIR" == "" then ./src else builtins.getEnv "PROJECT_DIR";
};
overrides = p2n.overrides.withDefaults (
self: super: {
grpcio = super.grpcio.override {
preferWheel = false;
};
# fix `No module named XXX`.
tomli = super.tomli.overridePythonAttrs (old: {
buildInputs = (old.buildInputs or [ ]) ++ [ self.flit-core ];
});
typing-extensions = super.typing-extensions.overridePythonAttrs (old: {
buildInputs = (old.buildInputs or [ ]) ++ [ self.flit-core ];
});
pathspec = super.pathspec.overridePythonAttrs (old: {
buildInputs = (old.buildInputs or [ ]) ++ [ self.flit-core ];
});
# add missing build tools
iniconfig = super.iniconfig.overridePythonAttrs (old: {
buildInputs = (old.buildInputs or [ ]) ++ [ self.setuptools self.hatchling self.hatch-vcs ];
});
urllib3 = super.urllib3.overridePythonAttrs (old: {
buildInputs = (old.buildInputs or [ ]) ++ [ self.setuptools self.hatchling self.hatch-vcs ];
});
# fix `Could not find a version that satisfies the requirement XXX (from versions: none)`
requests = super.requests.overridePythonAttrs (old: {
nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ self.setuptools-scm ];
});
}
);
};
gen-proto = pkgs.writeShellApplication {
name = "gen-proto";
text = ''
echo "Generate protocol proto files"
python -m grpc_tools.protoc \
-I=./protos/protocol \
--python_out=./src/apibara/protocol/proto \
--pyi_out=./src/apibara/protocol/proto \
--grpc_python_out=./src/apibara/protocol/proto \
protos/protocol/*
echo "Generate Starknet proto files"
python -m grpc_tools.protoc \
-I=./protos/starknet \
--python_out=./src/apibara/starknet/proto \
--pyi_out=./src/apibara/starknet/proto \
protos/starknet/*
'';
};
ci-test = pkgs.writeShellApplication {
name = "ci-test";
text = ''
pytest
'';
};
ci-build = pkgs.writeShellApplication {
name = "ci-build";
text = ''
poetry build
'';
};
in
{
formatter = pkgs.nixpkgs-fmt;
checks = {
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
nixpkgs-fmt.enable = true;
black.enable = true;
isort.enable = true;
};
};
};
devShells.default = apibara-sdk.env.overrideAttrs (oldAttrs: {
inherit (self.checks.${system}.pre-commit-check) shellHook;
LD_LIBRARY_PATH = "${pkgs.stdenv.cc.cc.lib}/lib";
buildInputs = with pkgs; [
stdenv.cc.cc.lib
protobuf
poetry
gen-proto
docker-client
ci-test
ci-build
];
});
}
);
}