1 { stdenv, fetchurl, glibc }:
3 stdenv.mkDerivation rec {
4 name = "clever-tools-${version}";
8 url = "https://clever-tools.cellar.services.clever-cloud.com/releases/${version}/clever-tools-${version}_linux.tar.gz";
9 sha256 = "1r0zjdr20si1hlikhzbpi57zmpd29zlik2frf7w46gjy1f6d1nhw";
12 libPath = stdenv.lib.makeLibraryPath [ stdenv.cc.cc glibc ];
15 tar --extract --file=$src
21 mv clever-tools-${version}_linux/clever $bin
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
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
40 # PRELUDE_POSITION = '1234 ' | 0
41 # ^-----20-chars-----^^------22-chars------^
42 # ^-- grep points here
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
49 shift_by=$(expr $new_size - $orig_size)
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
59 fix_offset PAYLOAD_POSITION
60 fix_offset PRELUDE_POSITION