-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathflake.nix
More file actions
202 lines (183 loc) · 5.01 KB
/
flake.nix
File metadata and controls
202 lines (183 loc) · 5.01 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
nixpkgs-depotdownloader.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
crane.url = "github:ipetkov/crane";
};
outputs =
{
nixpkgs,
nixpkgs-depotdownloader,
flake-utils,
rust-overlay,
crane,
...
}:
let
inherit (nixpkgs) lib;
in
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
(import rust-overlay)
(self: super: {
depotdownloader =
nixpkgs-depotdownloader.legacyPackages.${super.stdenv.hostPlatform.system}.depotdownloader;
})
];
};
python = pkgs.python311.withPackages (
p: with p; [
mariadb
numpy
packaging
scipy
]
);
rust-toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
craneLib = (crane.mkLib pkgs).overrideToolchain (
p:
((p.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml).override {
extensions = [
"clippy"
"rustfmt"
];
})
);
mkFileSet =
files:
lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions (
files
++ [
(craneLib.fileset.commonCargoSources ./.)
./crates/cs2kz/migrations
./.sqlx
./.example.env
]
);
};
fileSetForCrate =
crate:
mkFileSet [
(craneLib.fileset.commonCargoSources crate)
];
src = mkFileSet [ ];
commonArgs = {
inherit src;
strictDeps = true;
env = {
SQLX_OFFLINE = true;
};
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
crateArgs = commonArgs // {
inherit cargoArtifacts;
inherit (craneLib.crateNameFromCargoToml { inherit src; }) version;
};
cs2kz-api = craneLib.buildPackage (
crateArgs
// {
pname = "cs2kz-api";
src = fileSetForCrate ./crates/cs2kz-api;
cargoExtraArgs = "--bin=cs2kz-api";
nativeBuildInputs = [ pkgs.makeWrapper ];
preFixup = ''
wrapProgram $out/bin/cs2kz-api \
--prefix PATH : ${python}/bin
'';
}
);
generator = craneLib.buildPackage (
crateArgs
// {
pname = "generator";
src = fileSetForCrate ./crates/cs2kz-api;
cargoExtraArgs = "--bin=generator -Ffake";
nativeBuildInputs = [ pkgs.makeWrapper ];
preFixup = ''
wrapProgram $out/bin/generator \
--prefix PATH : ${python}/bin
'';
}
);
openapi-schema = craneLib.buildPackage (
crateArgs
// {
pname = "openapi";
src = fileSetForCrate ./crates/cs2kz-api;
cargoExtraArgs = "--bin=openapi";
}
);
in
{
checks = {
inherit cs2kz-api generator openapi-schema;
clippy = craneLib.cargoClippy (
commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--no-deps --all-features --all-targets -- -Dwarnings";
}
);
clippy-tests = craneLib.cargoClippy (
commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--no-deps --all-features --tests -- -Dwarnings";
}
);
rustfmt = craneLib.cargoFmt {
inherit src;
};
};
packages = {
inherit
cs2kz-api
generator
openapi-schema
python
;
dockerImage = pkgs.dockerTools.buildLayeredImage {
name = cs2kz-api.pname;
tag = cs2kz-api.version;
config = {
Cmd = [
"${cs2kz-api}/bin/cs2kz-api"
"--config"
"/etc/cs2kz-api.toml"
"--depot-downloader-path"
"${pkgs.depotdownloader}/bin/DepotDownloader"
];
};
};
};
devShells.default = pkgs.mkShell {
nativeBuildInputs = [
rust-toolchain
python
]
++ (with pkgs; [
docker-client
lazydocker
mariadb
mycli
sqlx-cli
tokio-console
depotdownloader
oha
]);
KZ_API_ENVIRONMENT = "local";
};
}
);
}