From f70ffaa7ef9452fd8e21a623bde1c4c595b9414f Mon Sep 17 00:00:00 2001 From: Kyle Gentle Date: Sun, 13 Dec 2020 12:44:27 -0500 Subject: [PATCH] Add mkPoetryEnv shell.nix examples to README It took me a while to figure this out, so I think it may be useful to add as a reference to future `poetry2nix` users. Related to and inspired by #186, #60. --- README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/README.md b/README.md index 5a99864..e212b4b 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,38 @@ poetry2nix.mkPoetryEnv { See [./tests/editable/default.nix](./tests/editable/default.nix) for a working example of an editable package. +#### Example shell.nix +The `env` attribute of the attribute set created by `mkPoetryEnv` contains a shell environment. + +```nix +{ pkgs ? import {} }: +let + myAppEnv = poetry2nix.mkPoetryEnv { + projectDir = ./.; + editablePackageSources = { + my-app = ./src; + }; + }; +in myAppEnv.env +``` + +#### Example shell.nix with external dependencies +For a shell environment including external dependencies, pass the app environment and dependency packages (for example, `pkgs.hello`) as build inputs to `pkgs.mkShell`. +```nix +{ pkgs ? import {} }: +let + myAppEnv = poetry2nix.mkPoetryEnv { + projectDir = ./.; + editablePackageSources = { + my-app = ./src; + }; + }; +in +pkgs.mkShell { + buildInputs = [ myAppEnv pkgs.hello ]; +} +``` + ### mkPoetryPackages Creates an attribute set of the shape `{ python, poetryPackages, pyProject, poetryLock }`. Where `python` is the interpreter specified, `poetryPackages` is a list of all generated python packages, `pyProject` is the parsed `pyproject.toml` and `poetryLock` is the parsed `poetry.lock` file. `mkPoetryPackages` takes an attribute set with the following attributes (attributes without default are mandatory):