aboutsummaryrefslogtreecommitdiffhomepage
path: root/clever-tools/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'clever-tools/default.nix')
-rw-r--r--clever-tools/default.nix51
1 files changed, 37 insertions, 14 deletions
diff --git a/clever-tools/default.nix b/clever-tools/default.nix
index 6c729a5..9ac69e6 100644
--- a/clever-tools/default.nix
+++ b/clever-tools/default.nix
@@ -1,36 +1,59 @@
1{ stdenv, fetchurl, glibc, nodegit }: 1{ stdenv, fetchurl, glibc }:
2 2
3stdenv.mkDerivation rec { 3stdenv.mkDerivation rec {
4 name = "clever-tools-${version}"; 4 name = "clever-tools-${version}";
5 version = "0.9.3"; 5 version = "1.1.0";
6 6
7 src = fetchurl { 7 src = fetchurl {
8 url = "https://clever-tools.cellar.services.clever-cloud.com/releases/${version}/clever-tools-${version}_linux.tar.gz"; 8 url = "https://clever-tools.cellar.services.clever-cloud.com/releases/${version}/clever-tools-${version}_linux.tar.gz";
9 sha256 = "adcae5af912dcbdc74d996b6e94767f24d16bf1bdcd5073797f999fe75b018a4"; 9 sha256 = "1lkwckmlz2gf41xmnzydpcbly0jcry3bn8lp570gha768ic7xmb1";
10 }; 10 };
11 11
12 buildInputs = [ nodegit ];
13
14 libPath = stdenv.lib.makeLibraryPath [ stdenv.cc.cc glibc ]; 12 libPath = stdenv.lib.makeLibraryPath [ stdenv.cc.cc glibc ];
15 13
16 nodegitLibrary = stdenv.lib.makeLibraryPath [ nodegit ];
17
18 installPhase = '' 14 installPhase = ''
19 tar --extract --file=$src linux/clever --transform 's/linux\///' 15 tar --extract --file=$src
20 bin=$out/bin/clever 16 bin=$out/bin/clever
21 mkdir -p $out/bin 17 mkdir -p $out/bin
22 mv clever $bin 18 mv clever $bin
23 ln -s "$nodegitLibrary/nodegit.node" "$out/bin/nodegit.node"
24 ''; 19 '';
25 20
26 dontStrip = "true"; 21 dontStrip = "true";
27 22
23 # See https://github.com/brendan-hall/nixpkgs/blob/e3b313bb59f49f10970205aafd44878d35da07e7/pkgs/development/web/now-cli/default.nix#L25
24 # There is no helper in nixpkgs lib right now
25 # The algorithm for zeit/pkg fix is given https://github.com/NixOS/nixpkgs/pull/48193
26 # it has been used for Unity3D as well https://github.com/NixOS/nixpkgs/pull/48643
28 preFixup = '' 27 preFixup = ''
29 bin=$out/bin/clever 28 bin=$out/bin/clever
30 patchelf \ 29 orig_size=$(stat --printf=%s $bin)
31 --set-rpath "$libPath" \ 30 patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $bin
32 --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \ 31 patchelf --set-rpath ${libPath} $bin
33 "$bin" 32 new_size=$(stat --printf=%s $bin)
33 ###### zeit-pkg fixing starts here.
34 # we're replacing plaintext js code that looks like
35 # PAYLOAD_POSITION = '1234 ' | 0
36 # [...]
37 # PRELUDE_POSITION = '1234 ' | 0
38 # ^-----20-chars-----^^------22-chars------^
39 # ^-- grep points here
40 #
41 # var_* are as described above
42 # shift_by seems to be safe so long as all patchelf adjustments occur
43 # before any locations pointed to by hardcoded offsets
44 var_skip=20
45 var_select=22
46 shift_by=$(expr $new_size - $orig_size)
47 function fix_offset {
48 # $1 = name of variable to adjust
49 location=$(grep -obUam1 "$1" $bin | cut -d: -f1)
50 location=$(expr $location + $var_skip)
51 value=$(dd if=$bin iflag=count_bytes,skip_bytes skip=$location \
52 bs=1 count=$var_select status=none)
53 value=$(expr $shift_by + $value)
54 echo -n $value | dd of=$bin bs=1 seek=$location conv=notrunc
55 }
56 fix_offset PAYLOAD_POSITION
57 fix_offset PRELUDE_POSITION
34 ''; 58 '';
35
36} 59}