-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
176 lines (157 loc) · 4.62 KB
/
flake.nix
File metadata and controls
176 lines (157 loc) · 4.62 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
{
description = "obix";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
advisory-db = {
url = "github:rustsec/advisory-db";
flake = false;
};
crane.url = "github:ipetkov/crane";
};
outputs = {
self,
nixpkgs,
flake-utils,
rust-overlay,
advisory-db,
crane,
}:
flake-utils.lib.eachDefaultSystem
(system: let
overlays = [
(import rust-overlay)
];
pkgs = import nixpkgs {
inherit system overlays;
};
rustVersion = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
rustToolchain = rustVersion.override {
extensions = [
"rust-analyzer"
"rust-src"
"rustfmt"
"clippy"
];
};
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
rustSource = pkgs.lib.cleanSourceWith {
src = craneLib.path ./.;
filter = path: type:
(builtins.match ".*\.sqlx/.*" path != null)
|| (builtins.match ".*deny\.toml$" path != null)
|| (craneLib.filterCargoSources path type);
};
commonArgs = {
src = rustSource;
SQLX_OFFLINE = "true";
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
nativeBuildInputs = with pkgs; [
rustToolchain
alejandra
sqlx-cli
cargo-nextest
cargo-audit
cargo-deny
mdbook
bacon
postgresql
docker-compose
ytt
podman
podman-compose
curl
];
devEnvVars = rec {
PGDATABASE = "pg";
PGUSER = "user";
PGPASSWORD = "password";
PGHOST = "127.0.0.1";
DATABASE_URL = "postgres://${PGUSER}:${PGPASSWORD}@${PGHOST}:5432/pg?sslmode=disable";
PG_CON = "${DATABASE_URL}";
};
podman-runner = pkgs.callPackage ./nix/podman-runner.nix {};
nextest-runner = pkgs.writeShellScriptBin "nextest-runner" ''
set -e
export PATH="${pkgs.lib.makeBinPath [
podman-runner.podman-compose-runner
pkgs.wait4x
pkgs.sqlx-cli
pkgs.cargo-nextest
pkgs.coreutils
pkgs.gnumake
rustToolchain
pkgs.stdenv.cc
]}:$PATH"
export DATABASE_URL="${devEnvVars.DATABASE_URL}"
export PG_CON="${devEnvVars.PG_CON}"
export PGDATABASE="${devEnvVars.PGDATABASE}"
export PGUSER="${devEnvVars.PGUSER}"
export PGPASSWORD="${devEnvVars.PGPASSWORD}"
export PGHOST="${devEnvVars.PGHOST}"
cleanup() {
echo "Stopping deps..."
${podman-runner.podman-compose-runner}/bin/podman-compose-runner down || true
}
trap cleanup EXIT
echo "Starting PostgreSQL..."
${podman-runner.podman-compose-runner}/bin/podman-compose-runner up -d
echo "Waiting for PostgreSQL to be ready..."
${pkgs.wait4x}/bin/wait4x postgresql "$DATABASE_URL" --timeout 120s
echo "Running database migrations..."
${pkgs.sqlx-cli}/bin/sqlx migrate run
echo "Running nextest..."
cargo nextest run --workspace --verbose
echo "Running doc tests..."
cargo test --doc --workspace
echo "Building docs..."
cargo doc --no-deps --workspace
echo "Tests completed successfully!"
'';
in
with pkgs; {
packages = {
nextest = nextest-runner;
};
checks = {
workspace-fmt = craneLib.cargoFmt commonArgs;
workspace-clippy = craneLib.cargoClippy (commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-features -- --deny warnings";
});
workspace-audit = craneLib.cargoAudit {
inherit advisory-db;
src = rustSource;
};
workspace-deny = craneLib.cargoDeny {
src = rustSource;
};
check-fmt = stdenv.mkDerivation {
name = "check-fmt";
src = ./.;
nativeBuildInputs = [alejandra];
dontBuild = true;
doCheck = true;
checkPhase = ''
alejandra -qc .
'';
installPhase = ''
mkdir -p $out
'';
};
};
devShells.default = mkShell (devEnvVars
// {
inherit nativeBuildInputs;
});
formatter = alejandra;
});
}