-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathflake.nix
133 lines (115 loc) · 3.6 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
125
126
127
128
129
130
131
132
133
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
crane.url = "github:ipetkov/crane";
};
outputs =
{
self,
nixpkgs,
utils,
rust-overlay,
crane,
...
}@inputs:
utils.lib.eachDefaultSystem (system:
let
overlays = [ (import inputs.rust-overlay) ];
pkgs = import nixpkgs { inherit system overlays; };
python = pkgs.python3.withPackages (p: with p; [
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: nixpkgs.lib.fileset.toSource {
root = ./.;
fileset = nixpkgs.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;
buildInputs = [ python ];
env = {
PYO3_PYTHON = "${python}/bin/python";
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";
});
openapi-schema = craneLib.buildPackage (crateArgs // {
pname = "openapi";
src = fileSetForCrate ./crates/cs2kz-api;
cargoExtraArgs = "--bin=openapi";
});
in
{
checks = {
inherit cs2kz-api 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 openapi-schema;
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
mycli
sqlx-cli
tokio-console
depotdownloader
oha
]);
PYO3_PYTHON = "${python}/bin/python";
};
});
}