!rWxyQqNqMUDLECdsIf:blad.is

Poetry2nix

321 Members
https://github.com/nix-community/poetry2nix61 Servers

Load older messages


SenderMessageTime
10 Mar 2022
@vengmark2:matrix.orgl0b0 *

Thank you! I ended up with a similar approach after a bunch of experimenting:

{ pkgs ? import
    (
      fetchTarball
        {
          name = "nixpkgs-21.11-2022-01-03";
          url = "https://github.com/NixOS/nixpkgs/archive/08370e1e271f6fe00d302bebbe510fe0e2c611ca.tar.gz";
          sha256 = "1s9g0vry5jrrvvna250y538i99zy12xy3bs7m3gb4iq64qhyd6bq";
        })
    { }
}:
let
  python = pkgs.python38;
  poetryEnv = pkgs.poetry2nix.mkPoetryEnv {
    projectDir = builtins.path { path = ./.; name = "geostore"; };
    inherit python;
    extraPackages = ps: [ ps.pip ];
  };
in
poetryEnv.env.overrideAttrs (
  oldAttrs: {
    buildInputs = [
      pkgs.nodePackages.aws-azure-login
      (pkgs.poetry.override {
        inherit python;
      })
    ];
  }
)

This way the poetry2nix env and the Nix shell end up with the same Python environment, rather than the same Python interpreter in two different Nix store directories.

19:41:53
@vengmark2:matrix.orgl0b0 *

Thank you! I ended up with a similar approach after a bunch of experimenting:

{ pkgs ? import
    (
      fetchTarball
        {
          name = "nixpkgs-21.11-2022-01-03";
          url = "https://github.com/NixOS/nixpkgs/archive/08370e1e271f6fe00d302bebbe510fe0e2c611ca.tar.gz";
          sha256 = "1s9g0vry5jrrvvna250y538i99zy12xy3bs7m3gb4iq64qhyd6bq";
        })
    { }
}:
let
  python = pkgs.python38;
  poetryEnv = pkgs.poetry2nix.mkPoetryEnv {
    projectDir = builtins.path { path = ./.; name = "geostore"; };
    inherit python;
    extraPackages = ps: [ ps.pip ];
  };
in
poetryEnv.env.overrideAttrs (
  oldAttrs: {
    buildInputs = [
      (pkgs.poetry.override {
        inherit python;
      })
    ];
  }
)

This way the poetry2nix env and the Nix shell end up with the same Python environment, rather than the same Python interpreter in two different Nix store directories.

19:42:18
11 Mar 2022
@luctielen:matrix.orgLuc Tielen joined the room.09:54:59
@luctielen:matrix.orgLuc TielenHello, trying out poetry2nix for managing the python dependencies at our company. So far it seems to work great, except for fetching some packages from a private artifactory with credentials. Browsing through the issues, I found https://github.com/nix-community/poetry2nix/pull/390, but it uses the "old" nix-shell and not the new flake approach. Are there any docs on how to fetch a python package like this?11:04:50
13 Mar 2022
@worldofgeese:one.ems.hostworldofgeeseHas anyone tried including Hylang in their Poetry2nix projects? 16:13:40
16 Mar 2022
@gdesforges:matrix.orgGuillaume Desforges joined the room.12:23:56
@gdesforges:matrix.orgGuillaume Desforges Hi! I can't build opencv using poetry2nix, I'm getting Exception: Not found: 'python/cv2/gapi/.*\.py'...
I made a minimal reproduction: https://github.com/GuillaumeDesforges/bug-poetry2nix-opencv
Any help would be most helpful 🙏
12:25:49
@gdesforges:matrix.orgGuillaume Desforgesfound the issue: opencv wants internet 🤦‍♂️14:30:33
@gdesforges:matrix.orgGuillaume Desforgeshttps://github.com/opencv/opencv/issues/2173014:30:34
@gdesforges:matrix.orgGuillaume Desforges changed their profile picture.14:31:29
17 Mar 2022
@michael_j_ward:matrix.orgmichael_j_ward joined the room.17:37:59
@michael_j_ward:matrix.orgmichael_j_ward If I have to add an override to get connectorx to install, should I open a PR to add it in to the repo? 18:20:48
@michael_j_ward:matrix.orgmichael_j_ward

basically the same as all the other

{ pkgs ? import <nixpkgs> {} }:
let
  myAppEnv = pkgs.poetry2nix.mkPoetryEnv {
    python = pkgs.python39;
    projectDir = ./.;
    editablePackageSources = {
      my-app = ./src;
    };
    overrides = pkgs.poetry2nix.overrides.withDefaults (
      self: super: {
        connectorx = super.connectorx.overrideAttrs (
          old: {
            buildInputs = old.buildInputs ++ [ pkgs.openssl ];
          }
        );
    });
  };
in myAppEnv.env
18:21:17
@michael_j_ward:matrix.orgmichael_j_ward ^^ for clarity, that's my shell.nix 18:27:04
18 Mar 2022
@michael_j_ward:matrix.orgmichael_j_ward Additional Q: is there a recommended way to keep poetry around in nix-shell? It feels weird to me that it's not available from mkPoetryEnv 12:00:28
@k900:0upti.meK900Just add it to your shell's `nativeBuildInputs12:06:01
@k900:0upti.meK900 * Just add it to your shell's nativeBuildInputs 12:06:02
@michael_j_ward:matrix.orgmichael_j_ward I apologize, I'm only a week in to learniing nix. I've looked around a bit, i feel like this should be trivial but i can't figure out where to update the shell's nativeBuildInputs 12:56:35
@k900:0upti.meK900 Just add nativeBuildInputs = [ pkgs.poetry ] to your mkShell call 12:58:54
@michael_j_ward:matrix.orgmichael_j_ward

Took me a bit but got it

in myAppEnv.env

becomes

in pkgs.mkShell {
  buildInputs = [ myAppEnv ];
  nativeBuildInputs = [ pkgs.poetry ];
}
13:15:42
@michael_j_ward:matrix.orgmichael_j_ward So that poetry ends up disconnected from the app environment, i.e. i can run pytest but poetry run pytest fails 13:19:00
@k900:0upti.meK900That is normal 13:20:34
@k900:0upti.meK900poetry2nix doesn't actually create a Poetry environment 13:20:50
@k900:0upti.meK900It translates the lock file directly into Nix 13:20:57
@michael_j_ward:matrix.orgmichael_j_ward

removing any x-y problem:

I'm attempting to set up the dev flow.

My understanding is we use shell.nix to get into your project-specific dev shell. From there you can add / remove dependencies, run tests et cetera.

Do you recommend sticking with a simpler shell.nix for that purpose, not using poetry2nix?

{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
    buildInputs = [ pkgs.python3 pkgs.poetry ];
}
13:28:28
@k900:0upti.meK900If you want Poetry to be managing the environment, then yes, probably13:36:02
@michael_j_ward:matrix.orgmichael_j_wardwell not so much for managing the python virtual environment, but i still want to use poetry for dependency resolution and locking, right?13:41:18
@k900:0upti.meK900Yes, you can do that with poetry2nix and something like direnv13:47:32
@k900:0upti.meK900To automatically reload the shell when the dependencies change13:47:47
@jmgilman:matrix.orgJoshua Gilman set a profile picture.22:17:56

Show newer messages


Back to Room ListRoom Version: 6