-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[small, flakes] How to make a flake with a python library, supporting arbitrary Python versions? #25
Comments
Since this has only been briefly covered in NH29 without getting into flakes at all: @t184256 if you end up with a satisfying complete solution, would you care to post it here (or make a PR to include it in a I imagine a minimal {
description = "Minimal example for Python Libraries as overlay";
outputs = { self, nixpkgs }: # implicitly gets `nixpkgs` from flake registry
let
system = "x86_64-linux";
myPyLibOverlay = final: prev: {
myPyLib = final.callPackage ./packages/myPyLib.nix { };
};
in
{
overlays = {
customPyLibs = final: prev: {
# pythonPackagesExtensions (PR #91850) merged Aug 6, 2022
pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [
myPyLibOverlay
#...
];
};
};
nixosConfigurations = {
someMachine = nixpkgs.lib.nixosSystem {
inherit system;
modules = [
{ nixpkgs.overlays = [ self.overlays.customPyLibs ]; }
./machines/some/configuration.nix
];
};
};
};
} Please correct me if I'm wrong. I don't fully grok flakes and flake best practices yet. |
Or using it in a flake package/app? Again, not sure if the |
I don't think the
I was asking that for a library I'm writing in the open, so I can share the resulting commit: t184256/asyncdbview@f0acee7 As I understood it, the minimal example would be something like this: {
description = "mylib/flake.nix example providing an overlay";
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; overlays = [ overlay ]; };
overlay = final: prev: {
pythonPackagesExtensions =
prev.pythonPackagesExtensions ++ [ mylib-pyextension ];
};
mylib-pyextension = pyFinal: pyPrev: {
mylib = pkgs.callPackage mylib-package { python3Packages = pyFinal; };
};
mylib-package = {python3Packages}:
python3Packages.buildPythonPackage {
pname = "mylib";
version = "0.0.1";
src = ./.;
};
in
{
overlays.default = overlay;
}
);
} {
description = "myapp/flake.nix example using the overlay";
inputs.mylib.url = "...";
outputs = { self, nixpkgs, flake-utils, mylib }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ mylib.overlays.${system}.default ];
};
python3Packages = pkgs.python312Packages; # <- non-standard
myapp = python3Packages.buildPythonPackage {
pname = "myapp";
version = "0.0.1";
src = ./.;
propagatedBuildInputs = with python3Packages; [ mylib ]; # <-
};
in
{
packages.default = myapp;
}
);
} |
Okay, so I played around a little bit, and I have a good bunch of questions related to this, that I think would be a good fit for a Nix Hour. @infinisil would you be willing to make a follow up on custom Python libraries and flakes? @t184256 would you participate in that? I could make it to any of the next two Nix Hours on 23rd ant 30th of May. For a little heads-up, here is my experiment repo. Since we haven't talked much about flakes on the Nix Hour it could also serve as a nice practical introduction to talk about it. I'd be willing to give a quick walk-through on air. Concrete things, I have problems with:
Some of these would nicely tie into topics you've covered on the Nix Hour. Also, I might be doing a few general beginners mistakes, that you people could be helpful in correcting. |
I've since noticed that overlays shouldn't go under |
For a python application, it's easy to find examples of flakes exporting a
package
.But what if I'm packaging a library and I want it to support a range of python versions? What am I supposed to export (a function taking pythonPackages and producing my library) and which flake output should this function be exposed under?
The text was updated successfully, but these errors were encountered: