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:
parent
89ebca89eb
commit
e6873dbd77
|
@ -9,18 +9,6 @@ nix-mode
|
|||
> "};" n
|
||||
"in" n
|
||||
> "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:
|
||||
;; mode: lisp-data
|
||||
|
|
|
@ -1,23 +1,24 @@
|
|||
{ pkgs, ... }:
|
||||
# MPLBACKEND
|
||||
{
|
||||
home.packages = with pkgs; [
|
||||
(python3.withPackages (
|
||||
let
|
||||
pythonEnv = (
|
||||
pkgs.python312.withPackages (
|
||||
ps: with ps; [
|
||||
python-lsp-server
|
||||
pylsp-rope
|
||||
rope
|
||||
isort
|
||||
flake8
|
||||
mypy
|
||||
pyyaml
|
||||
numpy
|
||||
xarray
|
||||
netcdf4
|
||||
matplotlib
|
||||
]
|
||||
))
|
||||
ruff
|
||||
)
|
||||
);
|
||||
in
|
||||
{
|
||||
home.packages = [
|
||||
pkgs.ruff
|
||||
pythonEnv
|
||||
];
|
||||
xdg.configFile."ruff/pyproject.toml".source = ./ruff.toml;
|
||||
}
|
||||
|
|
31
system/home/programming/python/pyshell.nix
Normal file
31
system/home/programming/python/pyshell.nix
Normal 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
|
||||
'';
|
||||
}
|
Loading…
Reference in a new issue