1{ stdenv, lib, fetchurl, dpkg, patchelf, qt5, libXtst, libXext, libX11, mkDerivation, libXScrnSaver, writeScript, common-updater-scripts, curl, pup }:
2
3let
4 version = "2.16.5.1";
5 src =
6 if stdenv.hostPlatform.system == "i686-linux" then fetchurl {
7 name = "rescuetime-installer.deb";
8 url = "https://www.rescuetime.com/installers/rescuetime_${version}_i386.deb";
9 sha256 = "1xrvyy0higc1fbc8ascpaszvg2bl6x0a35bzmdq6dkay48hnrd8b";
10 } else fetchurl {
11 name = "rescuetime-installer.deb";
12 url = "https://www.rescuetime.com/installers/rescuetime_${version}_amd64.deb";
13 sha256 = "09ng0yal66d533vzfv27k9l2va03rqbqmsni43qi3hgx7w9wx5ii";
14 };
15in mkDerivation rec {
16 # https://www.rescuetime.com/updates/linux_release_notes.html
17 inherit version;
18 pname = "rescuetime";
19 inherit src;
20 nativeBuildInputs = [ dpkg ];
21 # avoid https://github.com/NixOS/patchelf/issues/99
22 dontStrip = true;
23 unpackPhase = ''
24 mkdir pkg
25 dpkg-deb -x $src pkg
26 sourceRoot=pkg
27 '';
28 installPhase = ''
29 mkdir -p $out/bin
30 cp usr/bin/rescuetime $out/bin
31
32 ${patchelf}/bin/patchelf \
33 --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
34 --set-rpath "${lib.makeLibraryPath [ qt5.qtbase libXtst libXext libX11 libXScrnSaver ]}" \
35 $out/bin/rescuetime
36 '';
37
38 passthru.updateScript = writeScript "${pname}-updater" ''
39 #!${stdenv.shell}
40 set -eu -o pipefail
41 PATH=${lib.makeBinPath [curl pup common-updater-scripts]}:$PATH
42 latestVersion="$(curl -sS https://www.rescuetime.com/release-notes/linux | pup '.release:first-of-type h2 strong text{}' | tr -d '\n')"
43
44 for platform in ${lib.concatStringsSep " " meta.platforms}; do
45 # The script will not perform an update when the version attribute is up to date from previous platform run
46 # We need to clear it before each run
47 update-source-version ${pname} 0 $(yes 0 | head -64 | tr -d "\n") --system=$platform
48 update-source-version ${pname} "$latestVersion" --system=$platform
49 done
50 '';
51
52 meta = with lib; {
53 description = "Helps you understand your daily habits so you can focus and be more productive";
54 homepage = "https://www.rescuetime.com";
55 maintainers = with maintainers; [ cstrahan ];
56 sourceProvenance = with sourceTypes; [ binaryNativeCode ];
57 license = licenses.unfree;
58 platforms = [ "i686-linux" "x86_64-linux" ];
59 };
60}