1{
2 stdenv,
3 lib,
4 rustPlatform,
5 fetchFromGitHub,
6 installShellFiles,
7 pkg-config,
8 openssl,
9 libiconv,
10 testers,
11 sqlx-cli,
12 nix-update-script,
13}:
14
15rustPlatform.buildRustPackage rec {
16 pname = "sqlx-cli";
17 version = "0.8.6";
18
19 src = fetchFromGitHub {
20 owner = "launchbadge";
21 repo = "sqlx";
22 rev = "v${version}";
23 hash = "sha256-Trnyrc17KWhX8QizKyBvXhTM7HHEqtywWgNqvQNMOAY=";
24 };
25
26 cargoHash = "sha256-FxvzCe+dRfMUcPWA4lp4L6FJaSpMiXTqEyhzk+Dv1B8=";
27
28 buildNoDefaultFeatures = true;
29 buildFeatures = [
30 "native-tls"
31 "postgres"
32 "sqlite"
33 "mysql"
34 "completions"
35 ];
36
37 doCheck = false;
38 cargoBuildFlags = [ "--package sqlx-cli" ];
39
40 nativeBuildInputs = [
41 installShellFiles
42 pkg-config
43 ];
44
45 buildInputs =
46 lib.optionals stdenv.hostPlatform.isLinux [
47 openssl
48 ]
49 ++ lib.optionals stdenv.hostPlatform.isDarwin [
50 libiconv
51 ];
52
53 postInstall = ''
54 for shell in bash fish zsh; do
55 $out/bin/sqlx completions $shell > sqlx.$shell
56 installShellCompletion sqlx.$shell
57 done
58 '';
59
60 passthru.tests.version = testers.testVersion {
61 package = sqlx-cli;
62 command = "sqlx --version";
63 };
64
65 passthru.updateScript = nix-update-script { };
66
67 meta = with lib; {
68 description = "CLI for managing databases, migrations, and enabling offline mode with `sqlx::query!()` and friends";
69 homepage = "https://github.com/launchbadge/sqlx";
70 license = licenses.asl20;
71 maintainers = with maintainers; [
72 greizgh
73 xrelkd
74 fd
75 ];
76 mainProgram = "sqlx";
77 };
78}