New to nix, I have been wrestling with creating some derivations I need for work, such as one for Microsoft’s sqltoolsservice.
I am so grateful to the folks who have worked on autoPatchelfHook. It is remarkably easy to use. I did the following:
- added the packages providing the needed libraries to
buildInputs
- provided a list of libraries to skip in
autoPatchelfIgnoreMissingDeps
because autoPatchelfHook will stop at the first failure otherwise - In
postFixup
, I added somepatchelf --add-needed
andpatchelf --replace-needed
commands. WithpostFixup
running beforeautoPatchelfHook
, this allowed fixing some associations so thatautoPatchelfHook
will then link the correct libraries. Yay forpatchelf
. - Made sure
nativeBuildInputs
hadautoPatchelfHook
Everything else was automatic.
This involved days of figuring out various dependency problems. Essential for this was regular searching of the entire nixpkgs repo. Especially helpful were build-dotnet and powershell and aws-workspaces. These .NET packages had examples of critical workarounds for various issues I encountered.
I guess I just wanted to tell someone about the (eventual) success. And offer these tips for other new people who are wrestling with .NET issues.
Here is the derivation, if interested:
{ lib, stdenv, fetchurl, autoPatchelfHook, pkgs, ... }:
stdenv.mkDerivation rec {
pname = "ms-sqltoolsservice";
version = "4.11.0.10";
dotnet_version = "7.0";
dontUnpack = true;
buildInputs = with pkgs; [
stdenv.cc.cc
zlib
curl
openssl
lttng-ust
icu
libkrb5
];
dontStrip = true;
nativeBuildInputs = [ autoPatchelfHook ];
autoPatchelfIgnoreMissingDeps = [
"libcrypto.so.10"
"libssl.so.10"
];
src = fetchurl {
url = "https://github.com/microsoft/sqltoolsservice/releases/download/${version}/Microsoft.SqlTools.ServiceLayer-rhel-x64-net${dotnet_version}.tar.gz";
hash = "sha256-hdNZzJLYNO8QKId1q8wqrLLOhE3Wtgmk89vcOD5Ya/A=";
};
installPhase = ''
mkdir -p $out/bin
tar -x -C $out/bin -f $src
'';
postFixup = ''
patchelf \
--add-needed libicui18n.so \
--add-needed libicuuc.so \
$out/bin/libcoreclr.so \
$out/bin/*System.Globalization.Native.so
patchelf --replace-needed liblttng-ust.so.0 liblttng-ust.so $out/bin/libcoreclrtraceptprovider.so
patchelf \
--add-needed libgssapi_krb5.so \
$out/bin/*System.Net.Security.Native.so
patchelf --add-needed libssl.so \
$out/bin/*System.Security.Cryptography.Native.OpenSsl.so
'';
meta = {
description = "Microsoft SQL Tools API service that provides SQL Server data management capabilities";
license = lib.licenses.mit;
};
}