Poetry is a declarative project manager for Python. However, if you install Jupyter notebook with poetry on NixOS, it might fail to find some .so
files from the environment.
Combining the buildFHSUserEnv
solution in another topic here with poetry2nix.mkPoetryEnv
, we can get a working Jupyter environment with declarative dependency management portable to non-Nix environment.
Just place two files in the top-level directory of the Poetry project:
poetry-env.nix
{pkgs ? import <nixpkgs> {} }:
let
lib = pkgs.lib;
poetry2nix = pkgs.poetry2nix;
python37 = pkgs.python37;
in
poetry2nix.mkPoetryEnv {
python = python37;
pyproject = ./pyproject.toml;
poetrylock = ./poetry.lock;
}
poetry-env-fhs.nix
{
pkgs ? import <nixpkgs> {},
# This allows us to provide a command to run via `--argstr run COMMAND`.
run ? "bash"
}:
let
poetry-env = import ./poetry-env.nix { };
in
with pkgs; (buildFHSUserEnv {
name = "poetry-env-fhs";
targetPkgs = pkgs: with pkgs; [
# curl
# git
gcc
gnumake
python37Packages.poetry
pandoc # for pdf conversion
texlive.combined.scheme-full # for pdf conversion
which # a convenient tool in vertualized environments
] ++ [
poetry-env
];
runScript = "${run}";
profile = ''
# export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt
# export GIT_SSL_CAINFO="$SSL_CERT_FILE"
# export LANG=C.UTF-8
'';
}).env
Since it takes quite a while for mkPoetryEnv to build a package, you may want to
nix-build ./poetry-env.nix
to keep the build result from being GC-ed.
If two files would to be too much, they can also be joined together:
{
pkgs ? import <nixpkgs> {},
# This allows us to provide a command to run via `--argstr run COMMAND`.
run ? "bash"
}:
let
lib = pkgs.lib;
poetry2nix = pkgs.poetry2nix;
python37 = pkgs.python37;
poetry-env = poetry2nix.mkPoetryEnv {
python = python37; # Python package to use
pyproject = ./pyproject.toml; # Path to pyproject.toml
poetrylock = ./poetry.lock; # Path to poetry.lock
};
in
with pkgs; (buildFHSUserEnv {
name = "poetry-env-fhs";
targetPkgs = pkgs: with pkgs; [
# curl
# git
gcc
gnumake
python37Packages.poetry
pandoc # for pdf conversion
texlive.combined.scheme-full # for pdf conversion
which # a convenient tool in vertualized environments
] ++ [
poetry-env
];
runScript = "${run}";
profile = ''
# export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt
# export GIT_SSL_CAINFO="$SSL_CERT_FILE"
# export LANG=C.UTF-8
'';
}).env
I’m just a newbie here. Any advice will be appreciated.