Friends, I encountered an issue when building mkPoetryApplication.
I have a small base16 color library that I have submitted to PyPi
It is compiled using poetry.
I’d like to use it for scripts that I add declaratively to my NixOS configuration.
Now I’m writing a script using poetry2nix, but when I try to build the application, I get an error at the stage of building this package:
nix log /nix/store/gjjmxb6h3f6d47cc59z4hh3is1xivy15-python3.10-base16-colorlib-0.2.0.drv
# ....
Processing /tmp/nix-build-python3.10-base16-colorlib-0.2.0.drv-0/base16_colorlib-0.2.0
Running command Preparing metadata (pyproject.toml)
Preparing metadata (pyproject.toml) ... done
ERROR: Exception:
Here's a python traceback
It basically comes from pip
File "/nix/store/j73ikmqhvn2sjb536bpk9khrn2cgijy3-python3.10-pip-23.2.1/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 77, in _build_backend
obj = import_module(mod_path)
File "/nix/store/pzf6dnxg8gf04xazzjdwarm7s03cbrgz-python3-3.10.12/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
#....
ModuleNotFoundError: No module named 'poetry'
I know that the package can be installed on my local computer.
python3 -m venv venv
pip install base16-colorlib
pip freeze --> base16-colorlib==0.2.0
This is what flake.nix looks like now for the script and this library:
{
description = "i3lock-color-py preconf run script";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
};
outputs = { self, nixpkgs, ... }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
in {
packages.${system}.default = with pkgs; poetry2nix.mkPoetryApplication {
projectDir = self;
propagatedBuildInputs = [
i3lock-color
];
};
devShells.${system}.default = pkgs.mkShellNoCC {
shellHook = ''
echo
echo "█░█░█ █▀▀ █░░ █▀▀ █▀█ █▀▄▀█ █▀▀"
echo "▀▄▀▄▀ ██▄ █▄▄ █▄▄ █▄█ █░▀░█ ██▄"
echo "-- -- -- -- -- -- -- -- -- -- -"
echo
'';
packages = with pkgs; [
(poetry2nix.mkPoetryEnv { projectDir = self; })
];
};
};
}
This is what pyproject.toml looks like
[tool.poetry]
name = "i3lock-color-pytonic"
version = "0.1.0"
description = "Pre-configured script to run i3lock-color with the ability to change the color scheme and some parameters"
authors = ["MOIS3Y <stepan@zhukovsky.me>"]
license = "GPL-3.0-or-later"
repository = "https://github.com/MOIS3Y/i3lock-color-pytonic"
keywords = ["i3lock", "i3lock-color", "lockscreen"]
include = ["CHANGELOG.md"]
readme = "README.md"
packages = [{include = "i3lock_color"}]
[tool.poetry.dependencies]
python = "^3.10"
base16-colorlib = "^0.2.0"
click = "^8.1.7"
PyYAML = "^6.0.1"
[tool.poetry.group.dev.dependencies]
flake8 = "^6.1.0"
[tool.poetry.scripts]
i3lock-run = "i3lock_color.main:main"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
As you can see, there is nothing special, if you remove base16_colorlib everything comes together and works.
Of course, I could do without the library, but I don’t want to duplicate the code.
I also really want to understand why it is not working, as I find poetry2nix a very useful tool.
UPD:
I completely forgot to say that earlier they helped me package this as part of the system packages using packageOverrides
packageOverrides
And it worked.
In general, I understand how self: super works, but I don’t know where it can be applied in the case of p2nix