I somewhat maintain packages and libraries that don’t fit into nixpkgs
into my own flake.
Consumers (my own projects, or anyone else) just specify the flake as an input, and then can use the pamplemousse-flake.lib
, pamplemousse-flake.packages
, etc. into theirs.
However, I want now to package a python
module in a similar fashion.
I wrote the appropriate nix expression
{ ... }:
buildPythonPackage { ... }
referenced it into my flake.nix
. It builds fine locally using nix build .#python3.pkgs.<the package>
.
How should I expose it so that people can use python3.withPackages (ps: [ pamplemousse-flake.packages.x86_64-linux.python3.pkgs.<the package> ])
, and it would work with their python
installation?
Should I also provide an overlay for consumers to easily extend their python3
with my package? What would it look like?
3 Likes
I have the same problem. I have two flakes, A and B. A should expose a Python library that B then uses. I tried to formulate A as follows (see How to create an overlay for a python package in a flake for inspiration):
{
outputs = {}: {
overlays.default = final: prev: {
# Taken from
# https://discourse.nixos.org/t/how-to-create-an-overlay-for-a-python-package-in-a-flake/46247
pythonPackagesOverlays = (prev.pythonPackagesOverlays or [ ]) ++ [
(python-final: python-prev: {
mypackage = pkgs.python3Packages.callPackage ./mypackage.nix { };
})
];
python3 =
let
self = prev.python3.override {
inherit self;
packageOverrides = prev.lib.composeManyExtensions final.pythonPackagesOverlays;
};
in
self;
python3Packages = final.python3.pkgs;
};
}
}
And B then as:
{
inputs = "A";
outputs = {A}: let system = "x86_64-linux"; in {
overlays.default = final: prev: {
# my-application.nix uses "python3Packages.mypackage"
my-application = final.callPackage ./my-application.nix {};
};
packages.${system} =
let pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
};
in
{
my-application = pkgs.my-application;
};
};
}
But it doesn’t work. python3Packages
doesn’t contain mypackage
.
when I did a very similar thing in the post referenced by pimiddy, I used a custom nixpkgs github repo to create an overlay of nixpkgs. Check out this post where dropol explains how to do it. (in the end I took a slightly different approach that didn’t use flake-parts
). Then, using the flakes referenced in pimiddy’s post, I was able to import my custom python packages into any flake I want, by using my custom nixpkgs as an input to the flake.