Packaging/Quirks and Caveats: Difference between revisions

From NixOS Wiki
imported>Makefu
initial batch of nixos-users
 
imported>Mic92
No edit summary
Line 39: Line 39:




-----
=== GLib-GIO-Message: Using the 'memory' GSettings backend.  Your settings will not be saved or shared with ===
 
<code>GLib-GIO-Message: Using the 'memory' GSettings backend.  Your settings will not be saved or shared with</code>


Fixed by adding <code>wrapGAppsHook</code> to buildInputs:
Fixed by adding <code>wrapGAppsHook</code> to buildInputs:


<pre> buildInputs = [ ...  wrapGAppsHook ];</pre>
<syntaxHighlight lang="nix">
Sample PR in nixpkgs: * [https://github.com/NixOS/nixpkgs/pull/24617/files networkmanagerapplet]
buildInputs = [ ...  wrapGAppsHook ];
 
</syntaxHighlight>
Sample PR in nixpkgs:  
* [https://github.com/NixOS/nixpkgs/pull/24617/files networkmanagerapplet]


-----


For packaged python libs: <code>ImportError: libstdc++.so.6: cannot open shared object file: No such file</code>
For packaged python libs: <code>ImportError: libstdc++.so.6: cannot open shared object file: No such file</code>


Solution: According to the IRC, add <code>${stdenv.cc.cc.lib}/lib/libstdc++.so.6</code> to the search path.
Solution: According to the IRC, add <code>${stdenv.cc.cc.lib}/lib/libstdc++.so.6</code> to the search path.

Revision as of 10:41, 26 August 2017

A good start for packaging your first piece if software is the Quickstart Chapter in the nixpkgs manual Also see the Generic Algorithm on doing Packaging


Build software with Autotools

Add autoreconfHook to buildInputs to automatically build software which uses automake and autoconf:

  buildInputs = [ ...  autoreconfHook ];

Examples in nixpkgs: * samplicator

Package simple python scripts

For scripts like a single Python file, it is not necessary to specify src in mkDerivation. When you want to use buildPythonPackage the sources need to provide a setup.py file which also is overkill for a lot of projects. The default mkDerivation will attempt to unpack your source code. This can be prevented that by applying unpackPhase = ":"; (: is a no-op in shell scripts).

myscript-package = pkgs.stdenv.mkDerivation {
  name = "myscript";
  buildInputs = [
    (pkgs.python36.withPackages (pythonPackages: with pythonPackages; [
      consul
      six
      requests
    ]))
  ];
  unpackPhase = ":";
  installPhase = "install -m755 -D ${./myscript.py} $out/bin/myscript";
};

nix will automatically replace shebangs, for ex. #!/usr/bin/env python3 with dependencies given in buildInputs. As the derivation got pkgs.python36.withPackages (...) in buildInputs, it will create a virtualenv-like python wrapper. The python wrapper will have all specified dependencies and will be used to call the script.

In NixOS, the package can be put into environment.systemPackages, and myscript will be available as a global command.

Source: nh2 @ StackOverflow

A more lightweight alternative is to use nix-shell in the shebang line as described in this gist

Caveats

After packaging software and successfully generating an executable some functions of the package might still not work. This is a collection of error and how to fix them:


GLib-GIO-Message: Using the 'memory' GSettings backend. Your settings will not be saved or shared with

Fixed by adding wrapGAppsHook to buildInputs:

buildInputs = [ ...  wrapGAppsHook ];

Sample PR in nixpkgs:


For packaged python libs: ImportError: libstdc++.so.6: cannot open shared object file: No such file

Solution: According to the IRC, add ${stdenv.cc.cc.lib}/lib/libstdc++.so.6 to the search path.