Skip to content

Instantly share code, notes, and snippets.

@walkah
Created August 19, 2021 13:34
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 walkah/dff369189761d48642a409431dcf613f to your computer and use it in GitHub Desktop.
Save walkah/dff369189761d48642a409431dcf613f to your computer and use it in GitHub Desktop.
lotus.nix
{ pkgs, buildGoModule, fetchFromGitHub, rustPlatform }:
let
version = "1.11.1";
lotusSrc = fetchFromGitHub {
owner = "filecoin-project";
repo = "lotus";
rev = "v${version}";
sha256 = "0kvs9b3nzbkkrinrx9mnw0n41f32mcbd0bix3v98ng2h7lc3zj8a";
fetchSubmodules = true;
};
ipsnsecp = fetchFromGitHub {
owner = "ipsn";
repo = "go-secp256k1";
rev = "9d62b9f0bc52d16160f79bfb84b2bbf0f6276b03";
sha256 = "P0DVsWbuQ2BrHGX3eVvM0ucn9YM4XgP1j5vqNDhukr4=";
fetchSubmodules = true;
};
hidlib = fetchFromGitHub {
owner = "zondax";
repo = "hid";
rev = "302fd402163c34626286195dfa9adac758334acc";
sha256 = "cGJobeveSyJfWDDPBtU2RvnwbwdkvZa2+Nagtoh11/I=";
fetchSubmodules = true;
};
filcrypto = rustPlatform.buildRustPackage rec {
pname = "filcrypto";
version = "1.11.1";
doCheck = false; # requires elevated permissions
src = "${lotusSrc}/extern/filecoin-ffi/rust";
cargoSha256 = "sha256:18alwxbw6ix69ak94dij45zakjwzkx0902278yfihzr98cwk5ihh";
nativeBuildInputs = with pkgs; [ pkg-config ];
RUSTFLAGS = "--print native-static-libs";
preBuild = ''
LOGFILE=$(mktemp)
exec \
1> >(tee >(awk '{ system(""); print $0; system(""); }' >> "$LOGFILE")) \
2> >(tee >(awk '{ system(""); print $0; system(""); }' >> "$LOGFILE") >&2)
export OUT_DIR=$out
'';
postInstall = ''
local PRIVATE_LIBS=$(cat ''${LOGFILE} \
| grep native-static-libs\: \
| head -n 1 \
| cut -d ':' -f 3)
mkdir -p $out/lib/pkgconfig
sed -e "s;@VERSION;1.11.1;" \
-e "s;@PRIVATE_LIBS@;$PRIVATE_LIBS;" "filcrypto.pc.template" > $out/lib/pkgconfig/filcrypto.pc
mkdir -p $out/include
find -L . -type f -name filcrypto.h -exec cp -- "{}" $out/include/ \;
'';
buildInputs = with pkgs; [
opencl-headers
opencl-icd
openssl.out
openssl.dev
hwloc
];
};
ffi = buildGoModule {
pname = "filecoin-ffi";
version = version;
doCheck = false;
src = "${lotusSrc}/extern/filecoin-ffi";
vendorSha256 = "0wp5xbmrc49n85rdrc0wj9svv3kahnyqqhbjfcwp6al2r2zqlxks";
preBuild = ''
find ${filcrypto} -type f -exec ln -s {} . \;
'';
nativeBuildInputs = with pkgs; [ pkg-config ];
buildInputs = [ filcrypto ] ++ filcrypto.buildInputs;
};
in buildGoModule {
pname = "lotus";
version = version;
src = lotusSrc;
doCheck = false;
vendorSha256 = "1n29fapirchpp3w9c9b62ffqpwfgc7ynryiazkl4q06wqf7a5pvs";
subPackages = [ "cmd/lotus" ];
nativeBuildInputs = with pkgs; [ pkg-config ];
buildInputs = [ ffi ] ++ filcrypto.buildInputs;
postConfigure = ''
chmod u+w ./vendor/github.com/ipsn/go-secp256k1
cp -r ${ipsnsecp}/libsecp256k1 ./vendor/github.com/ipsn/go-secp256k1/libsecp256k1
chmod u+w ./vendor/github.com/zondax/hid
cp -r ${hidlib}/{libusb,hidapi} ./vendor/github.com/zondax/hid/
chmod u+w ./vendor/github.com/filecoin-project/filecoin-ffi
find ${filcrypto} -type f -exec ln -s "{}" ./vendor/github.com/filecoin-project/filecoin-ffi \;
'';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment