Related to this issue, I thought an elegant way to solve this would be to write an executable nix-shell
definition, which installs a target script from/with pip
and executes it. I have been experimenting with mach-nix
for this, but it doesn’t seem to work.
So say my goal is to instantiate an env in which I can install pandoc-xnos
and run it.
For now I came up with the following pandoc-xnos.nix
, which can be specified directly as filter executable for pandoc(omatic)
:
#!/usr/bin/env nix-shell
#!nix-shell --pure pandoc-xnos.nix
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
buildInputs = with pkgs; [
(python39.withPackages (p: with p; [ pip ]))
];
shellHook = ''
python -m venv $XDG_RUNTIME_DIR/pandoc-filters 1>&2
. $XDG_RUNTIME_DIR/pandoc-filters/bin/activate 1>&2
pip install pandoc-xnos 1>&2
pandoc-xnos
deactivate 1>&2
# rm -rf $XDG_RUNTIME_DIR/pandoc-filters 1>&2
'';
}
However this seems quite a dirty hack, since it doesn’t clean up and is far from pure. It would arguably be better to work via the nix store somehow and then rely on garbage collect? But then it would also be better if different python based pandoc
filters could use the same semi-temporary python env, at least between garbage collects?