Skip to content

Instantly share code, notes, and snippets.

@ThoenigAdrian
Created April 9, 2020 10:37
Show Gist options
  • Save ThoenigAdrian/bf520a3d96a8bd8f2f6d0b079e005a68 to your computer and use it in GitHub Desktop.
Save ThoenigAdrian/bf520a3d96a8bd8f2f6d0b079e005a68 to your computer and use it in GitHub Desktop.
# Import python packages which are installed in the nix store
# Note you NEED this if you install it via environment.systemPackages
# E.g environment.systemPackages = with pkgs; [ python27Packages.tensorflowWithCuda ]
# You DON'T NEED this if you do it like this:
# python-with-my-packages = pkgs.python27.withPackages (ps: with ps; [ tensorflowWithCuda]);
# environment.systemPackages = [ python-with-my-packages ]
import sys
from os.path import join
def import_nix(nix_store_path="/nix/store/y83iqaaq13k23lgyppbkaf4l6ilpsmjx-python2.7-tensorflow-gpu-1.14.0/"):
python_version = "python2.7" # replace with automatic call to get version of interpreter
sys.path.append(join(nix_store_path, "lib", python_version, "site-packages"))
propagated_build_inputs = "nix-support/propagated-build-inputs"
f = open(join(nix_store_path, propagated_build_inputs))
content = f.read()
f.close()
# skip last entry as it's just the path to python itself
# example:/nix/store/q20xz6iq493vha5425cbr4l6q190b39i-python-2.7.17
propagated_paths = content.split(" ")[:-2]
for p in propagated_paths:
# Recursively do this for all dependencies
import_nix(p)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment