summary refs log tree commit diff
path: root/pkgs/development/libraries/libssh/default.nix
blob: 8ea2ac72da0b3209680c061bd2656ab9374fe5e9 (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
{ stdenv, fetchurl, pkgconfig, cmake

# Optional Dependencies
, heimdal ? null, zlib ? null, libsodium ? null

# Crypto Dependencies
, openssl ? null, libgcrypt ? null
}:

with stdenv;
let
  # Prefer openssl
  cryptoStr = if shouldUsePkg openssl != null then "openssl"
    else if shouldUsePkg libgcrypt != null then "libgcrypt"
      else "none";
  crypto = {
    openssl = openssl;
    libgcrypt = libgcrypt;
    none = null;
  }.${cryptoStr};

  optHeimdal = shouldUsePkg heimdal;
  optZlib = shouldUsePkg zlib;
  optLibsodium = shouldUsePkg libsodium;
in

assert crypto != null;

stdenv.mkDerivation rec {
  name = "libssh-0.7.0";

  src = fetchurl {
    url = "https://git.libssh.org/projects/libssh.git/snapshot/libssh-0.7.0.tar.gz";
    sha256 = "1wfrdqhv97f4ycd9bcpgb6gw47kr7b2iq8cz5knk8a6n9c6870k0";
  };

  patches = [ ./0001-Reintroduce-ssh_forward_listen-Fixes-194.patch ];

  postPatch = ''
    # Fix headers to use libsodium instead of NaCl
    sed -i 's,nacl/,sodium/,g' ./include/libssh/curve25519.h src/curve25519.c
  '';

  cmakeFlags = [
    "-DWITH_GSSAPI=${if optHeimdal != null then "ON" else "OFF"}"
    "-DWITH_ZLIB=${if optZlib != null then "ON" else "OFF"}"
    "-DWITH_SSH1=OFF"
    "-DWITH_SFTP=ON"
    "-DWITH_SERVER=ON"
    "-DWITH_STATIC_LIB=OFF"
    "-DWITH_DEBUG_CRYPTO=OFF"
    "-DWITH_DEBUG_CALLTRACE=OFF"
    "-DWITH_GCRYPT=${if cryptoStr == "libgcrypt" then "ON" else "OFF"}"
    "-DWITH_PCAP=ON"
    "-DWITH_INTERNAL_DOC=OFF"
    "-DWITH_TESTING=OFF"
    "-DWITH_CLIENT_TESTING=OFF"
    "-DWITH_BENCHMARKS=OFF"
    "-DWITH_EXAMPLES=OFF"
    "-DWITH_NACL=${if optLibsodium != null then "ON" else "OFF"}"
  ] ++ stdenv.lib.optionals (optLibsodium != null) [
    "-DNACL_LIBRARY=${optLibsodium}/lib/libsodium.so"
    "-DNACL_INCLUDE_DIR=${optLibsodium}/include"
  ];

  nativeBuildInputs = [ pkgconfig cmake ];
  buildInputs = [ optHeimdal optZlib optLibsodium crypto ];

  meta = with stdenv.lib; {
    description = "SSH client library";
    license = licenses.lgpl2Plus;
    maintainers = with maintainers; [ sander urkud wkennington ];
    platforms = platforms.all;
  };
}