Questions surrounding python package contribution

So I’m trying to contribute a python package to nixpkgs and have a couple of questions. This is my build file thus far.

  1. This package has to other python package dependencies. Is it correct to place them in propagatedBuildInputs or should they be in nativeBuildInputs or buildInputs? The only thing I noticed when building this package is that it takes quite a bit of time (~20 min) since it’s also building the deps.

  2. When the package finished building it didn’t add it to the PATH. How would I go about making it add the package to the PATH env var automatically?

    shellHook = ''
        export PATH=$PATH:${src}

    Would this be correct?

From my experiences, you need to copy to ${out}/bin and it needs to have +x in the permissions.

Though you are using buildPythonPackage, which is for python libraries. Try buildPythonApplication instead, that is meant to be used for python packages that produce “runnable” output.

From my understanding:

  • nativeBuildInputs is for tools used to build the package, like compilers or make and therefore don’t need to be available at the packages runtime anymore.
  • buildINputs is used for libraries that the package needs to have available at compile time and runtime.
  • propagatedBuildInputs seems to be used for programs that need to be available at runtime, but that usage nix wasn’t able to figure out on their own.

I usually just use buildInputs until something does not work as expected :smiley: This is from the view of an unexperienced beginner though!

Thanks for the help! How do I get access to the out variable though? When I tried putting ${out}/bin in my hook I get an undefined variable error.

In the install it’s usually available.

But again, if you want to have a python package that provides an executable, then you need the application not package builder.

"... ${foo} ..." is used to interpolate nix expression foo into a string. However, out is defined as a shell variable, so just use something like $out/bin in your hook (so without curly braces).

1 Like

Thanks, that worked. What phase is the correct one to put this shell script though? Right now I’m using postInstall, but I’m not sure if that’s the one I should be using

postInstall = ''
    echo $out/bin
    export PATH=$out/bin:$PATH
    echo $PATH

Again, If you were using the application builder, then manually copying to $out/bin shouldn’t be necessary at all, have you tried that?

Yes, I’m currently using buildPythonApplication, but it’s not being added to PATH. This is my current build file

{ lib, python3Packages }:

python3Packages.buildPythonApplication rec {
  pname = "colorz";
  version = "1.0.3";

  src = python3Packages.fetchPypi {
   inherit pname version;
   sha256 = "0ghd90lgplf051fs5n5bb42zffd3fqpgzkbv6bhjw7r8jqwgcky0";

  propagatedBuildInputs = with python3Packages; [ pillow scipy ];

  # postInstall = ''
  #  echo $out/bin
  #  export PATH=$out/bin:$PATH
  #  echo $PATH

  meta = with lib; {
    description = "Color scheme generator";
    homepage =;
    license =;
    maintainers = with maintainers; [ skykanin ];

When I build this using nix-build -A colorz I even get a warning that it isn’t being added to PATH

That warning is issued by pip.

It does so because it’s not nix aware, I think you can ignore it…

Important is, whether or not the executable (or a symlink to it) ends up in your path when you install the derivation.

If you do a nix build and have the executable in ./result/bin then it will probably work in about all other cases.

1 Like

Ok, I do get the executable in ./result/bin/colorz and it works as intended