]> git.immae.eu Git - github/fretlink/clever-tools-nix.git/blame - clever-tools/default.nix
update to v1.6.2
[github/fretlink/clever-tools-nix.git] / clever-tools / default.nix
CommitLineData
e2b929c3 1{ stdenv, fetchurl, glibc }:
96ea4f91 2
e13be120
HAL
3stdenv.mkDerivation rec {
4 name = "clever-tools-${version}";
aff23eb8 5 version = "1.6.2";
96ea4f91 6
e13be120 7 src = fetchurl {
aff23eb8
CD
8 url = "https://clever-tools.clever-cloud.com/releases/${version}/clever-tools-${version}_linux.tar.gz";
9 sha256 = "00kmk1dxfs5d8qj74qj917gcssq0c1gm513wq4a7a4v5fm4zmirl";
e13be120 10 };
96ea4f91 11
e13be120 12 libPath = stdenv.lib.makeLibraryPath [ stdenv.cc.cc glibc ];
96ea4f91 13
615a1084 14 unpackPhase = ''
e2b929c3 15 tar --extract --file=$src
615a1084
HAL
16 '';
17
18 installPhase = ''
e13be120
HAL
19 bin=$out/bin/clever
20 mkdir -p $out/bin
615a1084 21 mv clever-tools-${version}_linux/clever $bin
e13be120 22 '';
96ea4f91 23
e13be120 24 dontStrip = "true";
96ea4f91 25
e2b929c3
HAL
26 # See https://github.com/brendan-hall/nixpkgs/blob/e3b313bb59f49f10970205aafd44878d35da07e7/pkgs/development/web/now-cli/default.nix#L25
27 # There is no helper in nixpkgs lib right now
28 # The algorithm for zeit/pkg fix is given https://github.com/NixOS/nixpkgs/pull/48193
29 # it has been used for Unity3D as well https://github.com/NixOS/nixpkgs/pull/48643
e13be120
HAL
30 preFixup = ''
31 bin=$out/bin/clever
e2b929c3
HAL
32 orig_size=$(stat --printf=%s $bin)
33 patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $bin
34 patchelf --set-rpath ${libPath} $bin
35 new_size=$(stat --printf=%s $bin)
36 ###### zeit-pkg fixing starts here.
37 # we're replacing plaintext js code that looks like
38 # PAYLOAD_POSITION = '1234 ' | 0
39 # [...]
40 # PRELUDE_POSITION = '1234 ' | 0
41 # ^-----20-chars-----^^------22-chars------^
42 # ^-- grep points here
43 #
44 # var_* are as described above
45 # shift_by seems to be safe so long as all patchelf adjustments occur
46 # before any locations pointed to by hardcoded offsets
47 var_skip=20
48 var_select=22
49 shift_by=$(expr $new_size - $orig_size)
50 function fix_offset {
51 # $1 = name of variable to adjust
52 location=$(grep -obUam1 "$1" $bin | cut -d: -f1)
53 location=$(expr $location + $var_skip)
54 value=$(dd if=$bin iflag=count_bytes,skip_bytes skip=$location \
55 bs=1 count=$var_select status=none)
56 value=$(expr $shift_by + $value)
57 echo -n $value | dd of=$bin bs=1 seek=$location conv=notrunc
58 }
59 fix_offset PAYLOAD_POSITION
60 fix_offset PRELUDE_POSITION
e13be120 61 '';
e13be120 62}