NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.84k stars 13.92k forks source link

Package fhem (home automation server) #16675

Closed Gomez closed 8 years ago

Gomez commented 8 years ago

Issue description

I try to get a fhem (http://fhem.de/fhem.html) run on my server, its a perl home automation server, here is my default.nix, it successfully builds:

{ stdenv, pkgconfig, perl, perlPackages, fetchurl }:

stdenv.mkDerivation rec {
  name = "fhem-${version}";
  version = "5.7";

  src = fetchurl {
    url = http://fhem.de/fhem-5.7.tar.gz;
    sha256 = "179fd251edb0bc7dbd775d7d6597fcfe7df88c2f7b39c5bbecf17defaa6b9539";
  };

  propagatedBuildInputs = [ pkgconfig perl perlPackages.JSON perlPackages.DeviceSerialPort ];

  patchPhase = ''
    substituteInPlace Makefile --replace /opt $out
    substituteInPlace fhem.cfg --replace /opt/log $out/log
  '';

  makeFlags = ''
        PREFIX=$(out)
        INSTALL=install
        DESTDIR=$(out)
        PERLLIB=$(out)/lib/perl5/site_perl
        PERL=${perl}/bin/perl
  '';

  meta = {
    description = "File Manager and User Shell for the GNU Project";
    homepage = http://www.midnight-commander.org;
    license = "GPLv2+";
    maintainers = [ stdenv.lib.maintainers.sander ];
  };
}

DeviceSerialPort looks like this:

{ buildPerlPackage, fetchurl }:

buildPerlPackage rec {
    name = "Device-SerialPort-1.04";
    src = fetchurl {
      url = "mirror://cpan/authors/id/C/CO/COOK/${name}.tar.gz";
      sha256 = "d392567cb39b4ea606c0e0acafd8ed72320311b995336ece5fcefcf9b150e9d7";
    };
    meta = {
      license = "";
    };
}

Steps to reproduce

If i start the server i get this errors:

 Can't locate JSON.pm in @INC (you may need to install the JSON module) (@INC contains: /root/.nix-profile/lib/perl5/site_perl /nix/var/nix/profiles/default/lib/perl5/site_perl /run/current-system/sw/lib/perl5/s
ite_perl/5.22.1/x86_64-linux-thread-multi /run/current-system/sw/lib/perl5/site_perl/5.22.1 /run/current-system/sw/lib/perl5/site_perl /nix/store/yz66grd0xjffb91pm1j05b181k0r2ip9-perl-5.22.1/lib/perl5/site_perl/
5.22.1/x86_64-linux-thread-multi /nix/store/yz66grd0xjffb91pm1j05b181k0r2ip9-perl-5.22.1/lib/perl5/site_perl/5.22.1 /nix/store/yz66grd0xjffb91pm1j05b181k0r2ip9-perl-5.22.1/lib/perl5/5.22.1/x86_64-linux-thread-mu
lti /nix/store/yz66grd0xjffb91pm1j05b181k0r2ip9-perl-5.22.1/lib/perl5/5.22.1 . /nix/store/gc3gpk3n2f8irrykkvy30z2vaiz7pcc1-fhem-5.7/fhem/FHEM) at /nix/store/gc3gpk3n2f8irrykkvy30z2vaiz7pcc1-fhem-5.7/fhem/FHEM/70
_XBMC.pm line 18, <$fh> line 360.

and:

2016.07.03 11:59:48.585 0: Can't locate JSON.pm in @INC (you may need to install the JSON module) (@INC contains: /root/.nix-profile/lib/perl5/site_perl /nix/var/nix/profiles/default/lib/perl5/site_perl /run/cur
rent-system/sw/lib/perl5/site_perl/5.22.1/x86_64-linux-thread-multi /run/current-system/sw/lib/perl5/site_perl/5.22.1 /run/current-system/sw/lib/perl5/site_perl /nix/store/yz66grd0xjffb91pm1j05b181k0r2ip9-perl-5
.22.1/lib/perl5/site_perl/5.22.1/x86_64-linux-thread-multi /nix/store/yz66grd0xjffb91pm1j05b181k0r2ip9-perl-5.22.1/lib/perl5/site_perl/5.22.1 /nix/store/yz66grd0xjffb91pm1j05b181k0r2ip9-perl-5.22.1/lib/perl5/5.2
2.1/x86_64-linux-thread-multi /nix/store/yz66grd0xjffb91pm1j05b181k0r2ip9-perl-5.22.1/lib/perl5/5.22.1 . /nix/store/gc3gpk3n2f8irrykkvy30z2vaiz7pcc1-fhem-5.7/fhem/FHEM) at /nix/store/gc3gpk3n2f8irrykkvy30z2vaiz7
pcc1-fhem-5.7/fhem/FHEM/31_HUEDevice.pm line 16, <$fh> line 413.
BEGIN failed--compilation aborted at /nix/store/gc3gpk3n2f8irrykkvy30z2vaiz7pcc1-fhem-5.7/fhem/FHEM/31_HUEDevice.pm line 16, <$fh> line 413.

I am new to nix / nixos, some1 able to gimme some pointers?

Technical details

bjornfor commented 8 years ago

I believe the typical way to solve issues like this is by wrapping the program with PERL5LIB environment variable. See example here: https://github.com/NixOS/nixpkgs/blob/master/pkgs/servers/monitoring/munin/default.nix#L106-118.

Gomez commented 8 years ago

thanks @bjornfor Unfortunaly no change: My default.nix:

{ stdenv, makeWrapper, pkgconfig, perl, perlPackages, fetchurl, DeviceSerialPort }:

stdenv.mkDerivation rec {
  name = "fhem-${version}";
  version = "5.7";

  src = fetchurl {
    url = http://fhem.de/fhem-5.7.tar.gz;
    sha256 = "179fd251edb0bc7dbd775d7d6597fcfe7df88c2f7b39c5bbecf17defaa6b9539";
  };

  buildInputs = [ makeWrapper pkgconfig perl perlPackages.JSON DeviceSerialPort ];

  patchPhase = ''
    substituteInPlace Makefile --replace /opt $out
    substituteInPlace fhem.cfg --replace /opt/log $out/log
  '';

  makeFlags = ''
        PREFIX=$(out)
        INSTALL=install
        DESTDIR=$(out)
        PERLLIB=$(out)/lib/perl5/site_perl
        PERL=${perl}/bin/perl
  '';

  postFixup = ''
    for file in "$out"/*.pm "$out"/*.pl; do
        wrapProgram "$file" \
          --set PERL5LIB "$out/lib/perl5/site_perl:${with perlPackages; stdenv.lib.makePerlPath [
                JSON DeviceSerialPort
                ]}"
    done
  '';

  meta = {
    description = "File Manager and User Shell for the GNU Project";
    homepage = http://www.midnight-commander.org;
    license = "GPLv2+";
    maintainers = [ stdenv.lib.maintainers.sander ];
  };
}
Gomez commented 8 years ago

Solved it:

postFixup = ''
        wrapProgram "$out"/fhem/fhem.pl \
                --set PERL5LIB "$out/lib/perl5/site_perl:${with perlPackages; stdenv.lib.makePerlPath [
                JSON DeviceSerialPort
                ]}"
  '';

thx @bjornfor !

bjornfor commented 8 years ago

@Gomez: Great!