This repository has been archived by the owner on Nov 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
flake.nix
175 lines (151 loc) · 5.49 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
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
{
description = "A thorough example of a featureful REST API in Axum";
inputs = {
crane.url = "github:ipetkov/crane";
crane.inputs.flake-compat.follows = "flake-compat";
crane.inputs.nixpkgs.follows = "nixpkgs";
crane.inputs.flake-utils.follows = "flake-utils";
flake-compat.url = "github:edolstra/flake-compat";
flake-compat.flake = false;
flake-utils.url = "github:numtide/flake-utils";
master.url = "nixpkgs/master";
nixpkgs.url = "nixpkgs/nixos-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
rust-overlay.inputs.flake-utils.follows = "flake-utils";
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = inputs@{ self, flake-utils, nixpkgs, ... }:
flake-utils.lib.eachSystem [ "aarch64-darwin" "x86_64-darwin" "x86_64-linux" ] (system:
let
maybeRosetta = if system == "aarch64-darwin" then
nixpkgs.legacyPackages.x86_64-darwin
else
nixpkgs.legacyPackages.${system};
pkgs = import nixpkgs {
inherit system;
overlays = [
(import inputs.rust-overlay)
(final: prev: { master = inputs.master.legacyPackages.${system}; })
];
};
sharedInputs = with pkgs;
[
cargo-deny
cargo-edit
cargo-expand
cargo-udeps
maybeRosetta.cargo-watch
cargo-whatfeatures
clang
git-cliff
just
lld
openssl.dev
pkg-config
zlib.dev
] ++ (with self.packages."${system}"; [
cargo-outdated
rust-analyzer
sccache
sqlx-cli
]) ++ lib.optionals (stdenv.isDarwin)
(with pkgs.darwin.apple_sdk.frameworks; [
CoreServices
Security
SystemConfiguration
]) ++ lib.optionals (stdenv.isLinux) [
cargo-tarpaulin
perf-tools
strace
valgrind
];
rustTools = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
src = ./.;
craneLib = (inputs.crane.mkLib pkgs).overrideScope' (final: prev: {
rustc = rustTools;
cargo = rustTools;
rustfmt = rustTools;
});
cargoArtifacts = craneLib.buildDepsOnly {
inherit src;
nativeBuildInputs = with pkgs; [ clang lld ];
};
axum-rest-example = craneLib.buildPackage {
inherit cargoArtifacts src;
# Tests are impure/stateful and dependent on Postgres
doCheck = false;
# We don't need these artifacts to run or provide a Docker artifact
doInstallCargoArtifacts = false;
nativeBuildInputs = with pkgs; [ clang lld ];
};
axum-rest-example-clippy = craneLib.cargoClippy {
inherit cargoArtifacts src;
nativeBuildInputs = with pkgs; [ clang lld rustTools ];
};
axum-rest-example-fmt = craneLib.cargoFmt { inherit src; };
app = flake-utils.lib.mkApp {
drv = self.packages."${system}".axum-rest-example;
};
in {
apps.axum-rest-example = app;
apps.default = app;
checks = {
inherit axum-rest-example axum-rest-example-clippy
axum-rest-example-fmt;
};
devShells.default = pkgs.mkShell {
name = "axum-rest-example-nightly";
nativeBuildInputs = [ rustTools ] ++ sharedInputs;
NIX_PATH = "nixpkgs=${nixpkgs}:master=${inputs.master}";
PROTOC = "${pkgs.protobuf}/bin/protoc";
PROTOC_INCLUDE = "${pkgs.protobuf}/include";
RUST_SRC_PATH = "${rustTools}/lib/rustlib/src/rust/library";
};
devShells.nightly = pkgs.mkShell {
nativeBuildInputs = [ pkgs.rust-bin.nightly.latest.default ]
++ sharedInputs;
RUSTFLAGS = "-Z macro-backtrace";
};
packages = {
inherit (pkgs.master) rust-analyzer sqlx-cli;
inherit (pkgs) sccache;
cargo-outdated = pkgs.symlinkJoin {
name = "cargo-outdated";
paths = [ pkgs.cargo-outdated ];
buildInputs = [ pkgs.makeWrapper ];
postBuild = ''
wrapProgram $out/bin/cargo-outdated \
--unset RUST_LOG
'';
};
clippy = pkgs.symlinkJoin {
name = "clippy";
paths = [ pkgs.clang rustTools pkgs.lld ];
buildInputs = [ pkgs.makeWrapper ];
postBuild = ''
wrapProgram $out/bin/cargo-clippy \
--prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.clang pkgs.lld ]}
'';
};
default = axum-rest-example;
# Uncomment to build Docker image without using a Docker daemon
docker = pkgs.dockerTools.streamLayeredImage {
name = "axum-rest-example";
tag = "latest";
contents = with self.packages.x86_64-linux; [ axum-rest-example ];
config = {
Cmd = [
"${self.packages.x86_64-linux.axum-rest-example}/bin/axum-rest-example"
];
Env = [ "RUST_LOG=debug" ];
};
};
inherit axum-rest-example;
gcroot = pkgs.linkFarmFromDrvs "axum-rest-example"
(with self.outputs; [
devShells."${system}".default.inputDerivation
devShells."${system}".nightly.inputDerivation
]);
};
});
}