-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
For python, how to use venvShellHook with numtide / devshell
#309
Labels
enhancement
New feature or request
Comments
numtide / devshell
numtide / devshell
Did you find a solution? |
@yajo my solution was not using numtide devshell but using flake devshell with flake as described here: https://fasterthanli.me/series/building-a-rust-service-with-nix/part-10 Here's a flake i use for one of my projects:
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
flake-parts = { url = "github:hercules-ci/flake-parts"; inputs.nixpkgs-lib.follows = "nixpkgs"; };
process-compose-flake.url = "github:Platonic-Systems/process-compose-flake";
};
outputs = inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
# https://community.flake.parts/process-compose-flake
inputs.process-compose-flake.flakeModule
];
systems = [ "x86_64-linux" "aarch64-linux" ];
perSystem = { config, pkgs, system, ... }:
let
pyPackages = pkgs.python311Packages;
in
{
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
overlays = [
(final: prev: {
unstable = import inputs.nixpkgs-unstable {
system = final.system;
config.allowUnfree = true;
};
})
];
};
process-compose = {
localpg = {
settings.processes = {
postgres-server = {
command = ''pg_ctl -o "-p $PGPORT -h $PGHOST" -D $PGDATA start'';
is_daemon = true;
shutdown = { command = "pg_ctl -D $PGDATA stop"; };
};
};
};
};
devShells = {
default = pkgs.mkShell {
name = "custom-py-shell";
venvDir = "./.venv";
nativeBuildInputs = [ ];
buildInputs = [
pkgs.python311
pyPackages.pip
pyPackages.venvShellHook
pkgs.poetry
pkgs.just # adhoc commands
];
packages = [
# debugging
#pkgs.memray
#pyPackages.objgraph
#pyPackages.pudb
pyPackages.ipython
pyPackages.isort
pyPackages.mypy
pkgs.ruff
pkgs.unstable.duckdb
# pg
pkgs.postgresql_16 # for exts: withPackages (p: [ p.pg_uuidv7 ]))
];
postShellHook = ''
mkdir -p $PGDATA
if [ -d $PGDATA ]; then
initdb -U postgres $PGDATA --auth=trust >/dev/null
fi
export LD_LIBRARY_PATH="${pkgs.lib.makeLibraryPath [
pkgs.stdenv.cc.cc
]}"
'';
};
ci = pkgs.mkShell {
name = "ci";
venvDir = "./.venv";
buildInputs = [
pkgs.poetry
pyPackages.venvShellHook
];
packages = [
pkgs.just
pyPackages.isort
pyPackages.mypy
pyPackages.pytest
pkgs.ruff
];
postShellHook = ''
export PROJECT_ROOT=$GITHUB_WORKSPACE
'';
};
};
};
};
} Hope it helps! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We can use venvShellHook with plain shell.nix with something like
And with vanilla flake with something like:
But with
numtide / devshell
it seems like I cannot use venvShellHook and hence no way to have the sweet virtual env created for me as I cd into the directory.The text was updated successfully, but these errors were encountered: