Add pyshell.nix helper function for making wrapped python shells

Just import, optionally changing python version or adding extra
packages (e.g. poetry) to the shell

Update default python env

Remove pyshell template from Emacs templates due to new change
This commit is contained in:
Evie Litherland-Smith 2024-12-17 11:54:22 +00:00
parent 89ebca89eb
commit e6873dbd77
3 changed files with 41 additions and 21 deletions

View file

@ -9,18 +9,6 @@ nix-mode
> "};" n > "};" n
"in" n "in" n
> "fhs.env") > "fhs.env")
(pyshell "let" n
> "pkgs = import " (p "<nixpkgs>") " { };" n
> "fix-python = (builtins.getFlake \"github:GuillaumeDesforges/fix-python\").packages.${pkgs.system}.default;" n
> "python3 = pkgs." (p "python3") ";" n
"in" n
"pkgs.mkShellNoCC {" n
> "packages = [python3 fix-python pkgs.uv];" n
> "shellHook = ''" n
> "export PYTHONPATH=$(readlink -f " (p "./.") "):$PYTHONPATH" n
> "export MPLBACKEND=" (p "TkAgg") n
> "'';"n
"}")
;; Local Variables: ;; Local Variables:
;; mode: lisp-data ;; mode: lisp-data

View file

@ -1,23 +1,24 @@
{ pkgs, ... }: { pkgs, ... }:
# MPLBACKEND let
{ pythonEnv = (
home.packages = with pkgs; [ pkgs.python312.withPackages (
(python3.withPackages (
ps: with ps; [ ps: with ps; [
python-lsp-server python-lsp-server
pylsp-rope
rope
isort isort
flake8 flake8
mypy mypy
pyyaml
numpy numpy
xarray xarray
netcdf4 netcdf4
matplotlib matplotlib
] ]
)) )
ruff );
in
{
home.packages = [
pkgs.ruff
pythonEnv
]; ];
xdg.configFile."ruff/pyproject.toml".source = ./ruff.toml; xdg.configFile."ruff/pyproject.toml".source = ./ruff.toml;
} }

View file

@ -0,0 +1,31 @@
{
pkgs ? import <nixpkgs> { },
python3 ? pkgs.python3,
extraPackages ? with pkgs; [ uv ],
}:
let
inherit (pkgs) lib;
ldlibs = lib.makeLibraryPath (
with pkgs;
[
stdenv.cc.cc
glibc
zlib
zstd
]
);
pythonWrapped = pkgs.symlinkJoin {
name = "python";
paths = [ python3 ];
buildInputs = [ pkgs.makeWrapper ];
postBuild = ''
for file in $out/bin/*; do wrapProgram "$file" --prefix LD_LIBRARY_PATH : "${ldlibs}"; done
'';
};
in
pkgs.mkShellNoCC {
packages = [ pythonWrapped ] ++ extraPackages;
shellHook = ''
[ -f .venv/bin/activate ] && source .venv/bin/activate
'';
}