My code, fauxmo: GitHub - n8henrie/fauxmo at nix-module
Having read and tried multiple variations from the reading:
- Nixpkgs 23.11 manual | Nix & NixOS
- Some nix commands not working because of overlay - #5 by brogos
- How to add custom python package? - #4 by earvstedt
- Error: rich should use `buildPythonPackage` or `toPythonModule` if it is to be part of the Python packages set - #7 by shadowrylander
- Add Python package via overlay
- Overriding Python Modules - #6 by SergeK
- Using python.withPackages with nixpkgs-overlays does not work · Issue #26487 · NixOS/nixpkgs · GitHub
- Python - NixOS Wiki
- Weird overlay behavior with python packages - #2 by FRidh
I am still really struggling to figure how to provide an overlay via my flake that can be used to successfully provide python3Packages.fauxmo.
It seemed like the pythonPackagesExtensions was the newest and most promising approach, so I left it commented out as I tried other approaches, but nothing has worked so far – when I import this overlay into my system, I can often get a successful build, but the resulting module has python with uvloop but no fauxmo.
I created a devShell in the flake that used the overlay, and it correctly builds and has fauxmo available (e.g. python -m fauxmo.cli --help). However, when I include this overlay in a system, the resulting systemd service can’t find the module – and for good reason, it’s not there:
$ systemctl cat fauxmo | awk -F= '/ExecStart/ { print $2 }' | xargs cat
#!/nix/store/xmwznc4kdln0rg4jwpmdfkpgyff01jmz-bash-5.2-p15/bin/bash
set -e
/nix/store/1bzhmyvlidmmpwh5j070bg9ga8im58cc-python3-3.11.6-env/bin/python -m fauxmo.cli -c "/home/n8henrie/git/fauxmo/config.json"
$ ls /nix/store/1bzhmyvlidmmpwh5j070bg9ga8im58cc-python3-3.11.6-env/lib/python3.11/site-packages/
__pycache__ README.txt sitecustomize.py _sysconfigdata__linux_aarch64-linux-gnu.py uvloop uvloop-0.19.0.dist-info
This makes me very confused. It seems to find the module at build time / doesn’t fail to build, but for some reason it’s not there.
To save a click, the crux of the module is:
systemd.services.${service_name} = let
pythonWithFauxmo =
pkgs.python3.withPackages
(ps:
with ps; [
fauxmo
uvloop
]);
after = ["network-online.target"];
in {
description = service_name;
inherit after;
requires = after;
script = let
verbosity =
if cfg.verbosity == 0
then ""
else "-" + lib.concatStrings (builtins.genList (_: "v") cfg.verbosity);
in ''${pythonWithFauxmo}/bin/python -m fauxmo.cli ${verbosity} -c "${cfg.configFile}"'';
my current version of the overlay:
overlays.default = _: prev: rec {
python3 = let
packageOverrides = _: _: {
inherit (self.outputs.packages.${prev.system}) fauxmo;
};
in
prev.python3.override {
inherit packageOverrides;
self = python3;
};
};
Have also tried (without success):
pythonPackagesExtensions =
prev.pythonPackagesExtensions
++ [
(
_: _: {
inherit (self.outputs.packages.${prev.system}) fauxmo;
}
)
];
};
When I try to build the package directly from the machine that includes the overlay, it find the package but fails:
$ nix build .#nixosConfigurations.homeslice.pkgs.python3.pkgs.fauxmo
...
error:
… in the condition of the assert statement
at /nix/store/52yawfmb2rz0sm07px5zcrgv3y78v27v-source/lib/customisation.nix:249:17:
248| in commonAttrs // {
249| drvPath = assert condition; drv.drvPath;
| ^
250| outPath = assert condition; drv.outPath;
… in the right operand of the OR (||) operator
at /nix/store/52yawfmb2rz0sm07px5zcrgv3y78v27v-source/pkgs/development/interpreters/python/passthrufun.nix:28:45:
27| if lib.isDerivation value then
28| lib.extendDerivation (valid value || throw "${name} should use `buildPythonPackage` or `toPythonModule` if it is to be part of the Python packages set.") {} value
| ^
29| else
(stack trace truncated; use '--show-trace' to show the full trace)
error: fauxmo should use `buildPythonPackage` or `toPythonModule` if it is to be part of the Python packages set.
Any ideas on why this is building successfully when I nixos-rebuild switch when the model is obviously missing at runtime?
I assume this message (when I try to build directly) is probably because I’m mixing nixpkgs somehow – a different set used for the overlay vs the system – or something like that (based on the link above regarding the rich python package).
Thanks for any help / suggestions!
EDIT: Should probably also include the python module in question; I changed it to use the callPackage pattern as I thought that could sometimes help with these issues (of mixing pkgs sets), but it made no difference:
{
lib,
python3Packages,
}: let
inherit (python3Packages) buildPythonPackage setuptools-scm;
in
buildPythonPackage {
pname = "fauxmo";
version =
builtins.head
(lib.findFirst (v: v != null) null
(builtins.map
(builtins.match "^__version__ = \"(.*)\"")
(lib.splitString "\n" (builtins.readFile ./src/fauxmo/__init__.py))));
src = lib.cleanSource ./.;
format = "pyproject";
propagatedBuildInputs = [setuptools-scm];
}