Wow! That was a tough one! Every time I think Iāve setup the hardest NixOS derivation I get a harder one!
Thanks to the comments above and a lot of searching and trial and error I eventually got to the bottom of the problem.
src
First, I had set up a local src
dir to make debugging the issue easier. However, ../steamvr_utils
didnāt seem to detect changes Iād made to the project so I had to keep nudging the version number to rebuild the NixOS.
This was fixed by using the following. Iām not exactly sure what this does (other than most likely ignores files in .gitignore as part of rebuild changes) but it meant I could update the source without nudging the version.
src = pkgs.nix-gitignore.gitignoreSource [ ] /data/code/steamvr_utils;
setuptools
I switched to setuptools. Some docs I was following was using setuptools and I didnāt have any investment in Hatchling so I just switched to that.
nativeBuildInputs = with python3Packages; [
setuptools
wrapPython
];
wrapper
I added a wrapper as per some of the suggestions above (thanks!). Not sure all of this is necessary, Iāll update once Iāve tested a bit more:
postFixup = ''
wrapProgram "$out/bin/steamvr_utils" \
--prefix PYTHONPATH : "$PYTHONPATH" \
--prefix PYTHONPATH : "$out/${python311.sitePackages}" \
--prefix PATH : "${python311}/bin"
'';
bluepy
steamvr_utils
uses bluepy
which needs setcap
run on the bluepy-helper
.
security.wrappers.bluepy-helper = {
owner = "root";
group = "root";
capabilities = "cap_net_raw,cap_net_admin+eip";
source = "${pkgs.python3Packages.bluepy}/${pkgs.python311.sitePackages}/bluepy/bluepy-helper";
};
This also meant Iād need to tweak the path that the bluepy library uses to the bluepy-helper
so instead of pointing to a relative path it points to the wrapped bluepy-helper
in /run/wrappers/
. If anyone knows of a nicer way to do this Iām all ears (perhaps through patching?). Relevant change in the bluepy library (Iāll be making a fork of this unless a better solution comes up):
diff --git a/bluepy/btle.py b/bluepy/btle.py
index 3fa3564..dff6c08 100755
--- a/bluepy/btle.py
+++ b/bluepy/btle.py
@@ -21,7 +21,7 @@ def preexec_function():
Debugging = False
script_path = os.path.join(os.path.abspath(os.path.dirname(__file__)))
-helperExe = os.path.join(script_path, "bluepy-helper")
+helperExe = os.path.join("/run/wrappers/bin/bluepy-helper")
restructuring of steamvr_utils
What I discovered here (and the main issue I was having) was that the script files werenāt present in the store once itād been built.
I eventually found that adding packages in the pyproject.toml
got them into the output:
[tool.setuptools]
packages = [
"src",
"src.config",
"src.images",
"src.steamvr_utils",
"src.steamvr_utils.audio",
"src.steamvr_utils.basestation_interface",
"src.steamvr_utils.pactl_interface",
]
Various folders needed __init__.py
files or they also didnāt get included.
Some assets needed adding to a MANIFEST.in
file in the root of the project alongside pyproject.toml
.
include src/config/*.yaml
include src/images/*.png
I can probably pull these out of src/
but Iām going to tidy things up a bit generally now that I have a better idea of whatās going on.
There are a few other bits which Iām still working out (like whether __init__.py
actually requires the imports or not. I might also go back and see if I can now configure it with the existing repo (rather than my fork) now I have a better understanding.
[project.scripts] what finally worked
Once I had the actually scripts in the store I finally understood what went into [project.scripts]
:
[project.scripts]
steamvr_utils = "src.steamvr_utils.steamvr_utils:main"
Iāll update this post once Iāve cleaned things up a bit.
Thanks again all.