fstamour
fstamour

Reputation: 797

Adding linenoise library to nixpkgs

I am on NixOS, trying to compile a c project which require the linenoise library (which is an alternative to readline). But linenoise is not available in the nixpkgs.

So, I am trying to add it myself. At the moment I have this:

{ stdenv, fetchgit }:

stdenv.mkDerivation rec {
  name = "linenoise-${version}";
  version = "git-2016-09-30";

  src = fetchgit {
    url = "https://github.com/antirez/linenoise.git";
    rev = "c894b9e59f02203dbe4e2be657572cf88c4230c3";
    sha256 = "0wasql7ph5g473zxhc2z47z3pjp42q0dsn4gpijwzbxawid71b4w";
  };

  meta = {
    homepage = https://github.com/antirez/linenoise;
    description = "A minimal, zero-config, BSD licensed, readline replacement.";
    platforms = stdenv.lib.platforms.unix;
  };
}

I have 2 problems:

1: Linenoise is just a pair of c header/source files that are meant to be included directly in the project that uses linenoise. In other words, there is no compilation to be done, just adding these files should be enough. With the current derivation is obviously tries to configure/make/make install but I simply don't know how to do otherwise.

2: Linenoise need to be accesible with pkg-config.

Upvotes: 1

Views: 203

Answers (1)

danbst
danbst

Reputation: 3623

It is very easy to bypass configure/make/make install steps in Nixpkgs. You can use buildCommand attribute, where you clearly specify HOW to transform source to package.

buildCommand = ''
  mkdir -p $out/include
  cp $src/linenoise.c $out/include/
  cp $src/linenoise.h $out/include/
'';

The trick with $src variable is simple too: almost every attribute you define in mkDerivation will be available in build command under same name. You could use src_libnoise = fetchgit ... and then refer to it as $src_libnoise.

As for pkg-config stuff, I don't know for sure if it respects include directory, so you have to figure out how pkg-config finds about it's includes.

Upvotes: 1

Related Questions