Skip to content

Commit

Permalink
chore(nix): auto-initialize venv and patch binary dependencies in it
Browse files Browse the repository at this point in the history
This makes it easier to set-up a development environment on
NixOS. `nix develop` will use a proper virtualenv, and all development
tools will be available there, `ruff` included.
  • Loading branch information
vlaci committed Jul 24, 2024
1 parent 6375081 commit 3a0c406
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,21 @@
(system:
with nixpkgsFor.${system}; {
default = mkShell {
packages = [
venvDir = "./.venv";
buildInputs = [
# A Python interpreter including the 'venv' module is required to bootstrap
# the environment.
python3Packages.python

# This executes some shell code to initialize a venv in $venvDir before
# dropping into the shell
python3Packages.venvShellHook

# This hook is used to patch downloaded binaries in venv to use libraries
# from the nix store.
autoPatchelfHook

unblob.runtimeDeps
ruff
pyright
python3Packages.pytest
python3Packages.pytest-cov
Expand All @@ -78,7 +90,18 @@
nvfetcher
];

env.LD_LIBRARY_PATH = lib.makeLibraryPath [ file ];
postVenvCreation =
let
apply_patches = lib.concatMapStringsSep
"\n"
(patch: "patch -f -p1 -d $VIRTUAL_ENV/lib/python3*/site-packages < ${patch}")
pkgs.python3Packages.python-magic.patches;
in
''
poetry install --all-extras --sync --with dev
autoPatchelf "$VIRTUAL_ENV/"
${apply_patches}
'';
};
});

Expand Down

0 comments on commit 3a0c406

Please sign in to comment.