Reputation: 1166
I'm trying to package a python application for Nix, but I'm finding that the majority of the documentation assumes that I want to package a library.
In order to do this, I looked at Rednotebook example (not for any particular reason other than I happened to know it was written in python), which can be found in python-packages, but as that file is so huge, here is the relevant part:
redNotebook = buildPythonPackage rec {
name = "rednotebook-1.8.1";
src = pkgs.fetchurl {
url = "mirror://sourceforge/rednotebook/${name}.tar.gz";
sha256 = "00b7s4xpqpxsbzjvjx9qsx5d84m9pvn383c5di1nsfh35pig0rzn";
};
# no tests available
doCheck = false;
propagatedBuildInputs = with self; [ pygtk pywebkitgtk pyyaml chardet ];
meta = {
homepage = http://rednotebook.sourceforge.net/index.html;
description = "A modern journal that includes a calendar navigation, customizable templates, export functionality and word clouds";
license = licenses.gpl2;
maintainers = with maintainers; [ tstrobel ];
};
};
My derivation looks like this:
{ pkgs ? import <nixpkgs> {} }:
let
requirements = import ./nix/requirements.nix { inherit pkgs; };
in
pkgs.python35Packages.buildPythonPackage rec {
name = "package-name";
version = "1.0.0";
namePrefix = "";
src = ./.;
doCheck = false;
propagatedBuildInputs = builtins.attrValues requirements.packages;
}
requirements.nix
was the output of pypi2nix
and requirements.packages
has type "list of derivations". Despite this when I cd into the resulting store path for Rednotebook there is a /bin
directory with some wrapper scripts. The store path for my app there is just a lib
an no /bin
How do I tell Nixpkgs that I have an application?
Upvotes: 2
Views: 2350
Reputation: 83
Was experimenting with building and installing a sample service written in Python.
Ended up using buildPythonApplication
in my installer
If you are leveraging setuptools
to distribute your app you need to have the entry_points
value in your setup
call:
from distutils.core import setup
setup(
...
entry_points = {
'console_scripts': ['sample_module = src.app:main']
}
src - source code folder app - entry point module name main - name of the entry point function
My whole build configuration was:
# sample.nix
with (import <nixpkgs> {});
python37.pkgs.buildPythonApplication rec {
pname = "sample_service";
version = "0.0.3";
src = ./sample_package;
meta = with lib; {
homepage = "https://www.example.com";
description = "Sample Python Service";
};
}
sample_package was the folder that contained 'src' folder and 'setup.py' located at the same level as above 'sample.nix' file.
At this point, if you run nix-build sample.nix
it will build and install the package for you. However, to make it available on the path you will need to capture the resulting path in the nix store and run:
nix-env -i <nix_store_path>
Upvotes: 2
Reputation: 192
buildPythonPackage
is to be used for libraries, that is, when you want it to expose its modules in site-packages
. buildPythonApplication
is for applications that just happen to be written in Python. In that case, when you include such a derivation in another derivation, you don't want to expose the libraries.
This separation is important because it may happen that a Python 3 environment calls a tool that is written in Python 2 and vice versa.
Note that at the time of writing this issue hasn't been completely solved yet, but at least python.buildEnv
or python.withPackages
will not include applications along with their dependencies.
Upvotes: 1
Reputation: 9895
There are buildPythonPackage and buildPythonApplication functions, but at the end of the day, they both call mkPythonDerivation.
A Python application with a simple Nix package you can reference is Ranger; which uses buildPythonApplication
. The resulting derivation contains a wrapper in /nix/store/PACKAGE/bin/
Upvotes: 2