nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at 20.03 87 lines 2.5 kB view raw
1{ stdenv, lib, fetchurl }: 2stdenv.mkDerivation rec { 3 pname = "now-cli"; 4 version = "15.8.7"; 5 6 # TODO: switch to building from source, if possible 7 src = fetchurl { 8 url = "https://github.com/zeit/now-cli/releases/download/${version}/now-linux.gz"; 9 sha256 = "1x6nsn9qmsy4hk7l2dsyabc7fxkwwwl1y1852vs4dgxi8w1hax93"; 10 }; 11 12 sourceRoot = "."; 13 unpackCmd = '' 14 gunzip -c $curSrc > now-linux 15 ''; 16 17 buildPhase = ":"; 18 19 installPhase = '' 20 mkdir $out 21 mkdir $out/bin 22 cp now-linux $out/bin/now 23 ''; 24 25 # now is a node program packaged using zeit/pkg. 26 # thus, it contains hardcoded offsets. 27 # patchelf shifts these locations when it expands headers. 28 29 # this could probably be generalised into allowing any program packaged 30 # with zeit/pkg to be run on nixos. 31 32 preFixup = let 33 libPath = lib.makeLibraryPath [stdenv.cc.cc]; 34 in '' 35 36 orig_size=$(stat --printf=%s $out/bin/now) 37 38 patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $out/bin/now 39 patchelf --set-rpath ${libPath} $out/bin/now 40 chmod +x $out/bin/now 41 42 new_size=$(stat --printf=%s $out/bin/now) 43 44 ###### zeit-pkg fixing starts here. 45 # we're replacing plaintext js code that looks like 46 # PAYLOAD_POSITION = '1234 ' | 0 47 # [...] 48 # PRELUDE_POSITION = '1234 ' | 0 49 # ^-----20-chars-----^^------22-chars------^ 50 # ^-- grep points here 51 # 52 # var_* are as described above 53 # shift_by seems to be safe so long as all patchelf adjustments occur 54 # before any locations pointed to by hardcoded offsets 55 56 var_skip=20 57 var_select=22 58 shift_by=$(expr $new_size - $orig_size) 59 60 function fix_offset { 61 # $1 = name of variable to adjust 62 location=$(grep -obUam1 "$1" $out/bin/now | cut -d: -f1) 63 location=$(expr $location + $var_skip) 64 65 value=$(dd if=$out/bin/now iflag=count_bytes,skip_bytes skip=$location \ 66 bs=1 count=$var_select status=none) 67 value=$(expr $shift_by + $value) 68 69 echo -n $value | dd of=$out/bin/now bs=1 seek=$location conv=notrunc 70 } 71 72 fix_offset PAYLOAD_POSITION 73 fix_offset PRELUDE_POSITION 74 75 ''; 76 dontStrip = true; 77 78 79 80 meta = with stdenv.lib; { 81 homepage = https://zeit.co/now; 82 description = "The Command Line Interface for Now - Global Serverless Deployments"; 83 license = licenses.asl20; 84 platforms = platforms.linux; 85 maintainers = [ maintainers.bhall ]; 86 }; 87}