about summary refs log tree commit diff
path: root/pkgs/applications/misc/hubstaff/default.nix
blob: d4c199d48939ac7c23f0f98d1e87aa451321c824 (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
82
83
84
85
86
87
{ lib, stdenv, fetchurl, unzip, makeWrapper, libX11, zlib, libSM, libICE
, libXext , freetype, libXrender, fontconfig, libXft, libXinerama
, libXfixes, libXScrnSaver, libnotify, glib , gtk3, libappindicator-gtk3
, curl, writeShellScript, common-updater-scripts, xmlstarlet }:

let
  url = "https://app.hubstaff.com/download/7473-standard-linux-1-6-24-release";
  version = "1.6.24-094b0af9";
  sha256 = "sha256:1jwyl51lljxn6hnkp07bvgw60bqmq3gb0rdgvxmd7r8x3y3xshx1";

  rpath = lib.makeLibraryPath
    [ libX11 zlib libSM libICE libXext freetype libXrender fontconfig libXft
      libXinerama stdenv.cc.cc.lib libnotify glib gtk3 libappindicator-gtk3
      curl libXfixes libXScrnSaver ];

in

stdenv.mkDerivation {
  pname = "hubstaff";
  inherit version;

  src = fetchurl { inherit sha256 url; };

  nativeBuildInputs = [ unzip makeWrapper ];

  unpackCmd = ''
    # MojoSetups have a ZIP file at the end. ZIP’s magic string is
    # most often PK\x03\x04. This has worked for all past updates,
    # but feel free to come up with something more reasonable.
    dataZipOffset=$(grep --max-count=1 --byte-offset --only-matching --text ''$'PK\x03\x04' $curSrc | cut -d: -f1)
    dd bs=$dataZipOffset skip=1 if=$curSrc of=data.zip 2>/dev/null
    unzip -q data.zip "data/*"
    rm data.zip
  '';

  dontBuild = true;

  installPhase = ''
    # remove files for 32-bit arch to skip building for this arch
    # but add -f flag to not fail if files were not found (new versions dont provide 32-bit arch)
    rm -rf x86 x86_64/lib64

    opt=$out/opt/hubstaff
    mkdir -p $out/bin $opt
    cp -r . $opt/

    for f in "$opt/x86_64/"*.bin.x86_64 ; do
      patchelf --set-interpreter $(cat ${stdenv.cc}/nix-support/dynamic-linker) $f
      wrapProgram $f --prefix LD_LIBRARY_PATH : ${rpath}
    done

    ln -s $opt/x86_64/HubstaffClient.bin.x86_64 $out/bin/HubstaffClient

    # Why is this needed? SEGV otherwise.
    ln -s $opt/data/resources $opt/x86_64/resources
  '';

  # to test run:
  # nix-shell maintainers/scripts/update.nix --argstr package hubstaff
  # nix-build -A pkgs.hubstaff
  passthru.updateScript = writeShellScript "hubstaff-updater" ''
    set -eu -o pipefail

    # Create a temporary file
    temp_file=$(mktemp)

    # Fetch the appcast.xml and save it to the temporary file
    curl --silent --output "$temp_file" https://app.hubstaff.com/appcast.xml

    # Extract the latest release URL for Linux using xmlstarlet
    installation_script_url=$(${xmlstarlet}/bin/xmlstarlet sel -t -v '//enclosure[@sparkle:os="linux"]/@url' "$temp_file")
    version=$(${xmlstarlet}/bin/xmlstarlet sel -t -v '//enclosure[@sparkle:os="linux"]/@sparkle:version' "$temp_file")

    sha256=$(nix-prefetch-url "$installation_script_url")

    ${common-updater-scripts}/bin/update-source-version hubstaff "$version" "sha256:$sha256" "$installation_script_url"
  '';

  meta = with lib; {
    description = "Time tracking software";
    homepage = "https://hubstaff.com/";
    sourceProvenance = with sourceTypes; [ binaryNativeCode ];
    license = licenses.unfree;
    platforms = [ "x86_64-linux" ];
    maintainers = with maintainers; [ michalrus srghma ];
  };
}