I have created a derivation to run STATA, which comes with a binary after installing.
The derivation is
with import <nixpkgs> {};
stdenv.mkDerivation rec {
name = "stata-${version}";
version = "15";
system = builtins.currentSystem;
src = ./stata15;
builder = builtins.toFile "builder.sh" ''
source $stdenv/setup
runHook preInstall
cp -r $src $out
runHook postInstall
'';
buildInputs = [
pkgs.stdenv.cc.cc glib libpng12 gtk2-x11 atk gnome2.pango cairo gdk_pixbuf freetype fontconfig zlib libpng ncurses5
];
}
and after
nix-build stata.nix
nix-env -i <path>
it is installed in the store. However, when I run the binary from the store, I get ‘No such file or directory’.
What am I doing wrong?
jhartma
2
I got it figured out. For anybody interested:
with import <nixpkgs> {};
stdenv.mkDerivation rec {
name = "stata-${version}";
version = "15";
system = builtins.currentSystem;
src = ./stata15;
sourceRoot = ".";
dontConfigure = true;
dontBuild = true;
installPhase = ''
mkdir -p $out/bin
cp -R stata15 $out/
# symlink the binary to bin/
ln -s $out/stata15/xstata-mp $out/bin/stata
'';
preFixup = let
# we prepare our library path in the let clause to avoid it become part of the input of mkDerivation
libPath = lib.makeLibraryPath [ stdenv.cc.cc.lib glib gnome2.gtk atk gnome2.pango gdk-pixbuf cairo freetype fontconfig.lib libpng12 ];
in ''
patchelf \
--set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
--set-rpath "${libPath}" \
$out/stata15/xstata-mp
'';
meta = with stdenv.lib; {
homepage = https://www.stata.com/;
description = "Data analysis";
license = licenses.free;
platforms = platforms.linux;
maintainers = [ xxx ];
};
}
Note that I patched xstata-mp, if you need the SE version, just patch this one.
3 Likes
it works! commit to nixpkgs!