summaryrefslogtreecommitdiff
path: root/pkgs/applications/misc/subsurface/default.nix
blob: 7922e5fd0eb64ee75327a5d946983f3acc868dab (plain)
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
{
  lib,
  stdenv,
  fetchFromGitHub,
  autoreconfHook,
  writeShellScriptBin,
  cmake,
  wrapQtAppsHook,
  pkg-config,
  qmake,
  curl,
  grantlee,
  hidapi,
  libgit2,
  libssh2,
  libusb1,
  libxml2,
  libxslt,
  libzip,
  zlib,
  qtbase,
  qtconnectivity,
  qtlocation,
  qtsvg,
  qttools,
  qtpositioning,
  libxcomposite,
  bluez,
  writeScript,
}:

let
  version = "6.0.5504";

  subsurfaceSrc = (
    fetchFromGitHub {
      owner = "Subsurface";
      repo = "subsurface";
      rev = "28ad7132d2283a3fc06872de6526bc19c077d203";
      hash = "sha256-PQwBfm4oPGLU1HRFIcbgTYOYLeVhmEBgN5U8fnUMMlQ=";
      fetchSubmodules = true;
    }
  );

  libdc = stdenv.mkDerivation {
    pname = "libdivecomputer-ssrf";
    inherit version;

    src = subsurfaceSrc;

    sourceRoot = "${subsurfaceSrc.name}/libdivecomputer";

    nativeBuildInputs = [
      autoreconfHook
      pkg-config
    ];

    buildInputs = [
      zlib
      libusb1
      bluez
      hidapi
    ];

    enableParallelBuilding = true;

    meta = {
      homepage = "https://www.libdivecomputer.org";
      description = "Cross-platform and open source library for communication with dive computers from various manufacturers";
      maintainers = with lib.maintainers; [ mguentner ];
      license = lib.licenses.lgpl21;
      platforms = lib.platforms.all;
    };
  };

  googlemaps = stdenv.mkDerivation rec {
    pname = "googlemaps";
    version = "0.0.0.2";

    src = fetchFromGitHub {
      owner = "vladest";
      repo = "googlemaps";
      rev = "v.${version}";
      hash = "sha256-PfSLFQeCeVNcCVDCZehxyNLQGT6gff5jNxMW8lAaP8c=";
    };

    nativeBuildInputs = [ qmake ];

    buildInputs = [
      qtbase
      qtlocation
      libxcomposite
    ];

    dontWrapQtApps = true;

    pluginsSubdir = "lib/qt-${qtbase.qtCompatVersion}/plugins";

    installPhase = ''
      mkdir -p $out $(dirname ${pluginsSubdir}/geoservices)
      mkdir -p ${pluginsSubdir}/geoservices
      mv *.so ${pluginsSubdir}/geoservices
      mv lib $out/
    '';

    meta = {
      inherit (src.meta) homepage;
      description = "QtLocation plugin for Google maps tile API";
      maintainers = [ ];
      license = lib.licenses.mit;
      platforms = lib.platforms.all;
    };
  };

  get-version = writeShellScriptBin "get-version" ''
    echo -n ${version}
  '';

in
stdenv.mkDerivation {
  pname = "subsurface";
  inherit version;

  src = subsurfaceSrc;

  postPatch = ''
    install -m555 -t scripts ${lib.getExe get-version}
  '';

  buildInputs = [
    bluez
    curl
    googlemaps
    grantlee
    libdc
    libgit2
    libssh2
    libxml2
    libxslt
    libzip
    qtbase
    qtconnectivity
    qtsvg
    qttools
    qtpositioning
  ];

  nativeBuildInputs = [
    cmake
    wrapQtAppsHook
    pkg-config
  ];

  cmakeFlags = [
    "-DLIBDC_FROM_PKGCONFIG=ON"
    "-DNO_PRINTING=OFF"
  ];

  passthru = {
    inherit version libdc googlemaps;
    updateScript = writeScript "update-subsurface" ''
      #!/usr/bin/env nix-shell
      #!nix-shell -i bash -p git common-updater-scripts

      set -eu -o pipefail
      tmpdir=$(mktemp -d)
      pushd $tmpdir
      git clone -b current https://github.com/subsurface/subsurface.git
      cd subsurface
      sed -i '1s/#!\/bin\/bash/#!\/usr\/bin\/env bash/' ./scripts/get-version.sh
      # this returns 6.0.????-local
      new_version=$(./scripts/get-version.sh | cut -d '-' -f 1)
      new_rev=$(git rev-list -1 HEAD)
      popd
      update-source-version subsurface "$new_version" --rev="$new_rev"
      rm -rf $tmpdir
    '';
  };

  meta = {
    description = "Divelog program";
    mainProgram = "subsurface";
    longDescription = ''
      Subsurface can track single- and multi-tank dives using air, Nitrox or TriMix.
      It allows tracking of dive locations including GPS coordinates (which can also
      conveniently be entered using a map interface), logging of equipment used and
      names of other divers, and lets users rate dives and provide additional notes.
    '';
    homepage = "https://subsurface-divelog.org";
    license = lib.licenses.gpl2;
    maintainers = with lib.maintainers; [ mguentner ];
    platforms = lib.platforms.all;
  };
}