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