summary refs log tree commit diff
path: root/pkgs/development/tools/diesel-cli/default.nix
blob: a2c1af2607d1eaefa064645ee6306a82ac5810bc (plain) (blame)
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
{ stdenv, lib, rustPlatform, fetchFromGitHub, openssl, pkg-config, Security
, sqliteSupport ? true, sqlite
, postgresqlSupport ? true, postgresql
, mysqlSupport ? true, mariadb, zlib, libiconv
}:

assert lib.assertMsg (sqliteSupport == true || postgresqlSupport == true || mysqlSupport == true)
  "support for at least one database must be enabled";

let
  inherit (lib) optional optionals optionalString;
  features = optional sqliteSupport "sqlite"
    ++ optional postgresqlSupport "postgres"
    ++ optional mysqlSupport "mysql";
in

rustPlatform.buildRustPackage rec {
  pname = "diesel-cli";
  version = "1.4.1";

  src = fetchFromGitHub {
    owner = "diesel-rs";
    repo = "diesel";
    # diesel and diesel_cli are independently versioned. diesel_cli
    # 1.4.1 first became available in diesel 1.4.5, but we can use
    # a newer diesel tag.
    rev = "v1.4.6";
    sha256 = "0c8a2f250mllzpr20j7j0msbf2csjf9dj8g7j6cl04ifdg7gwb9z";
  };

  patches = [
    # Fixes:
    #    Compiling diesel v1.4.6 (/build/source/diesel)
    # error: this `#[deprecated]` annotation has no effect
    #    --> diesel/src/query_builder/insert_statement/mod.rs:205:1
    #     |
    # 205 | / #[deprecated(
    # 206 | |     since = "1.2.0",
    # 207 | |     note = "Use `<&'a [U] as Insertable<T>>::Values` instead"
    # 208 | | )]
    #     | |__^ help: remove the unnecessary deprecation attribute
    #     |
    #     = note: `#[deny(useless_deprecated)]` on by default
    ./fix-deprecated.patch
  ];

  cargoBuildFlags = [ "--no-default-features" "--features" "${lib.concatStringsSep "," features}" ];
  cargoPatches = [ ./cargo-lock.patch ];
  cargoSha256 = "060r90dvdi0s5v3kjagsrrdb4arzzbkin8v5563rdpv0sq1pi3bm";

  nativeBuildInputs = [ pkg-config ];

  buildInputs = [ openssl ]
    ++ optional stdenv.isDarwin Security
    ++ optional (stdenv.isDarwin && mysqlSupport) libiconv
    ++ optional sqliteSupport sqlite
    ++ optional postgresqlSupport postgresql
    ++ optionals mysqlSupport [ mariadb zlib ];

  buildAndTestSubdir = "diesel_cli";

  checkPhase = optionalString sqliteSupport ''
    (cd diesel_cli && cargo check --features sqlite)
  '';

  doInstallCheck = true;
  installCheckPhase = ''
    $out/bin/diesel --version
  '';

  # Fix the build with mariadb, which otherwise shows "error adding symbols:
  # DSO missing from command line" errors for libz and libssl.
  NIX_LDFLAGS = optionalString mysqlSupport "-lz -lssl -lcrypto";

  meta = with lib; {
    description = "Database tool for working with Rust projects that use Diesel";
    homepage = "https://github.com/diesel-rs/diesel/tree/master/diesel_cli";
    license = with licenses; [ mit asl20 ];
    maintainers = with maintainers; [ ];
  };
}