celenity/Dove
3
67
Fork
You've already forked Dove
7

fix: nix flake - don't build python venv #58

Merged
celenity merged 1 commit from :dev into dev 2025年12月26日 02:21:38 +01:00
Contributor
Copy link

introducing a patch to not create a python venv when using the nix flake

introducing a patch to not create a python venv when using the nix flake

@ddogfoodd Thanks for the PR! But, I feel like we should find a better solution for this. Would it be possible to detect that we're on Nix, and if so, set a variable that would prevent the creation of the pip environment? For an example of what I envision this looking look, you can see here for how I currently handle this with macOS.

Also, do you mind explaining why the behavior of creating a python venv isn't desirable for Nix (I'm not saying that I disagree with you - I'm just not very familiar with Nix, so I'm genuinely not sure as to why)?

@ddogfoodd Thanks for the PR! But, I feel like we should find a better solution for this. Would it be possible to detect that we're on Nix, and if so, set a variable that would prevent the creation of the pip environment? For an example of what I envision this looking look, you can see [here](https://codeberg.org/celenity/Dove/src/commit/6d86ac2efba527555c6143fd641d5fabfac13008/build/env.sh#L35) for how I currently handle this with macOS. Also, do you mind explaining why the behavior of creating a python venv isn't desirable for Nix *(I'm not saying that I disagree with you - I'm just not very familiar with Nix, so I'm genuinely not sure as to why)*?
Author
Contributor
Copy link

AFAIK nix (including flakes) is sandboxed i.e. offline during build by default.
Required dependencies have to be fetched before the build. Usually this means fetching the source code and importing other nix packages.

I believe the flake currently fails, because the build.sh is run which then tries to upgrade pip and install lxml while offline. We don't even need to, as the flake already imports lxml as a nix derivation / package.

Python venvs can bring further pain on NixOS, when python packages assume required C libraries in a certain location, while nix keeps them somewhere in the nix-store. This shouldn't apply here but is another reason to just skip the venv as long as we don't need it.

I agree and would have done it differently if I knew how. Apparently, we can check for the existence of /etc/NIXOS to detect NixOS, but that would't work on other OS using the nix package manager (https://discourse.nixos.org/t/detect-that-bash-script-is-running-under-nixos/11402/6). Is $OSTYPE a darwin thing or do we set it?
I assume we can set an environment variable during the flakes buildPhase, then skip the venv part if it is set.

Will try later.

AFAIK nix (including flakes) is sandboxed i.e. offline during build by default. Required dependencies have to be fetched before the build. Usually this means fetching the source code and importing other nix packages. I believe the flake currently fails, because the `build.sh` is run which then tries to upgrade pip and install `lxml` while offline. We don't even need to, as the flake already imports `lxml` as a nix derivation / package. Python venvs can bring further pain on NixOS, when python packages assume required C libraries in a certain location, while nix keeps them somewhere in the nix-store. This shouldn't apply here but is another reason to just skip the venv as long as we don't need it. I agree and would have done it differently if I knew how. Apparently, we can check for the existence of `/etc/NIXOS` to detect NixOS, but that would't work on other OS using the nix package manager (https://discourse.nixos.org/t/detect-that-bash-script-is-running-under-nixos/11402/6). Is `$OSTYPE` a darwin thing or do we set it? I assume we can set an environment variable during the flakes buildPhase, then skip the venv part if it is set. Will try later.
Author
Contributor
Copy link

Environment variable works, wasn't too sure about the naming. How about this?

Environment variable works, wasn't too sure about the naming. How about this?
celenity left a comment
Copy link

LGTM, thanks!

LGTM, thanks!
Sign in to join this conversation.
No reviewers
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
celenity/Dove!58
Reference in a new issue
celenity/Dove
No description provided.
Delete branch ":dev"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?