Skip to content

Instantly share code, notes, and snippets.

@ptitfred
Last active June 18, 2018 00:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ptitfred/a47fac62aa20e7da887b3edc84db8b43 to your computer and use it in GitHub Desktop.
Save ptitfred/a47fac62aa20e7da887b3edc84db8b43 to your computer and use it in GitHub Desktop.
Patch nodegit prebuilt x86_64 library

What's that

This is an attempt to install clever-tools in a Nix environment.

How to use it

nix-env -i -f default.nix

This should add clever to your PATH.

{ pkgs }:
let
version = "0.9.3";
nodegit = import ./nodegit.nix { inherit pkgs; };
stdenv = pkgs.stdenv;
glibc = pkgs.glibc;
fetchurl = pkgs.fetchurl;
libs = [ stdenv.cc.cc nodegit glibc ];
in
stdenv.mkDerivation rec {
name = "clever-cli-${version}";
buildInputs = [ nodegit pkgs.nodejs-6_x ];
src = fetchurl {
url = "https://clever-tools.cellar.services.clever-cloud.com/releases/${version}/clever-tools-${version}_linux.tar.gz";
sha256 = "adcae5af912dcbdc74d996b6e94767f24d16bf1bdcd5073797f999fe75b018a4";
};
buildPhase = ":";
libPath = stdenv.lib.makeLibraryPath libs;
nodegitLibrary = stdenv.lib.makeLibraryPath [ nodegit ];
installPhase = ''
tar --extract --file=$src linux/clever --transform 's/linux\///'
bin=$out/bin/clever
mkdir -p $out/bin
mv clever $bin
ln -s "$nodegitLibrary/nodegit.node" "$out/bin/nodegit.node"
'';
dontStrip = "true";
preFixup = ''
bin=$out/bin/clever
patchelf \
--set-rpath "$libPath" \
--set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
"$bin"
'';
}
{ pkgs ? import <nixpkgs>{} }:
let clever-tools = import ./clever-tools.nix { inherit pkgs; };
in clever-tools
{ pkgs }:
let
version = "0.20.3";
stdenv = pkgs.stdenv;
fetchurl = pkgs.fetchurl;
curl = pkgs.curl.override {
sslSupport = false;
gnutlsSupport = true;
};
glibc = pkgs.glibc;
openssl = pkgs.openssl;
libs = [ stdenv.cc.cc curl glibc openssl ];
in
assert pkgs.stdenv.system == "x86_64-linux";
stdenv.mkDerivation {
name = "nodegit-${version}";
src = fetchurl {
url = "https://nodegit.s3.amazonaws.com/nodegit/nodegit/nodegit-v${version}-node-v51-linux-x64.tar.gz";
sha256 = "d022a88e58fa70f78b59b475fa6ecc6724d372a779b132264cf571f71bc50020";
};
buildPhase = ":";
libPath = stdenv.lib.makeLibraryPath libs;
installPhase = ''
tar --extract --file=$src Release/nodegit.node --transform 's/Release\//linux-/'
lib=$out/lib/nodegit.node
mkdir -p $out/lib
mv linux-nodegit.node $lib
'';
preFixup = ''
lib=$out/lib/nodegit.node
patchelf --set-rpath "$libPath" "$lib"
'';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment