!rWxyQqNqMUDLECdsIf:blad.is

Poetry2nix

330 Members
https://github.com/nix-community/poetry2nix62 Servers

Load older messages


SenderMessageTime
23 Jan 2022
@k900:0upti.meK900If you want to use poetry2nix from git instead of the one in nixpkgs, you can use the overlay in the flake14:10:10
@mou_bugtracker:matrix.orgmou confusing. can i do import of git hosted flake in nix repl? to explore it and experiment 14:11:08
@k900:0upti.meK900 You can with builtins.getFlake 14:11:23
@mou_bugtracker:matrix.orgmouthanks14:11:30
@k900:0upti.meK900

But basically you want something like

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable-small";
    flake-utils.url = "github:numtide/flake-utils";
    poetry2nix = {
      url = "github:nix-community/poetry2nix";
      inputs.nixpkgs.follows = "nixpkgs";
      inputs.flake-utils.follows = "flake-utils";
    };
  };

  outputs = { self, nixpkgs, flake-utils, poetry2nix }:
    flake-utils.lib.eachDefaultSystem
      (system:
        let
          pkgs = import nixpkgs {
            overlays = [ poetry2nix.overlay ];
            inherit system;
          };
        in
        {
          packages.your-app = pkgs.poetry2nix.mkPoetryApplication {
               # stuff
          };
        }
      )
}
14:12:38
@mou_bugtracker:matrix.orgmou

also expression in lambda passed to eachDefaultSystem contains this binding

  23           inherit system;
  24           overlays = [ self.overlay ];
  25         };

Does it import nixpkgs with revision locked by flake, or just version defined as channel?

14:13:24
@k900:0upti.meK900 import nixpkgs re-imports the nixpkgs input 14:14:00
@k900:0upti.meK900 import <nixpkgs> imports the channel 14:14:05
@k900:0upti.meK900 (and will fail if you're not using --impure) 14:14:14
@mou_bugtracker:matrix.orgmou *

also expression in lambda passed to eachDefaultSystem contains this binding

  22         pkgs = import nixpkgs {
  23           inherit system;
  24           overlays = [ self.overlay ];
  25         };

Does it import nixpkgs with revision locked by flake, or just version defined as channel?

14:14:31
@mou_bugtracker:matrix.orgmouthanks for clarification14:14:45
@mou_bugtracker:matrix.orgmouSo poetry2nix flake made all other functionality available through applying overlay to nixpkgs? So it kind of glue between everything defined in this flake modules and all other nix infrastructure?14:37:58
@k900:0upti.meK900poetry2nix is included in nixpkgs14:38:30
@k900:0upti.meK900The overlay just replaces the stable version in nixpkgs with the latest version from git14:38:43
@k900:0upti.meK900Well, not really latest, but whichever one you have pinned14:38:50
@mou_bugtracker:matrix.orgmou i'm trying to figure out how to work with shell and all my attempts to use mkPoetryEnv and using nix develop produces environments without python interpreter itself (and without poetry cli, but this is minor) even if derivation is called python3-3.9.9-env. I'm using snipets from Readme but have feelings i missed something important for understanding. 14:50:53
@mou_bugtracker:matrix.orgmouBut according to python mkPoetryEnv returns result of python.withPackages. I guess i need to read about this function too14:52:46
@mou_bugtracker:matrix.orgmou I found problem. I should use as devShell not the entire attirbute set returned by mkPoetryEnv, but only attribute env 15:16:12
@nialov:matrix.orgnialov joined the room.15:23:20
@nialov:matrix.orgnialovI have a question, does poetry2nix use nixpkgs to download ANY of the python packages defined in poetry.lock or does it build all from source?15:24:09
@k900:0upti.meK900It does, but exact cache hits are rare 15:30:22
@k900:0upti.meK900So you'll end up building most things from source 15:30:44
@nialov:matrix.orgnialovOkay thanks! So if you create a default.nix for nixpkgs and submit it, then want to use that same package from poetry2nix you will probably have to redefine some build steps and dependencies twice for a complicated package?15:39:35
@k900:0upti.meK900No15:39:58
@k900:0upti.meK900poetry2nix will use the package definitions from nixpkgs15:40:13
@k900:0upti.meK900But the build environment is slightly different usually, so you'll get rebuuldsn15:40:38
@k900:0upti.meK900* But the build environment is slightly different usually, so you'll get rebuilds15:40:45
@nialov:matrix.orgnialovAh okay, rebuilds are of course fine. Will it use the definition if the version for the package is different?15:41:52
@k900:0upti.meK900Yes 15:42:00
@mou_bugtracker:matrix.orgmou

looks like i almost get my first working flake with dev environment but ended up with code duplication to solve external library build dependency on poetry. And i can not think of good solution to extract duplication. Maybe anybody can suggest good idiomatic solution?

  description = "Exyaru (Atushka) project"; inputs.flake-utils.url = "github:numtide/flake-utils";
  inputs.nixpkgs.url = "github:NixOS/nixpkgs";
  inputs.poetry2nix.url = "github:nix-community/poetry2nix";

  outputs = { self, nixpkgs, flake-utils, poetry2nix }: {
      # Nixpkgs overlay providing the application
      overlay = nixpkgs.lib.composeManyExtensions [ poetry2nix.overlay
        (final: prev: {
          # The application
          exyaru = prev.poetry2nix.mkPoetryApplication {
            projectDir = ./.;
            overrides = prev.poetry2nix.defaultPoetryOverrides.extend ( self: super: {
              uengine = super.uengine.overridePythonAttrs (
                old: {
                  buildInputs = (old.buildInputs or [ ]) ++ [ self.poetry ];
                }
              );
            });
          };
        })
      ];
    } // (flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs {
          inherit system;
          overlays = [ self.overlay ];
        };
      in
      rec {
        apps = {
          exyaru = pkgs.exyaru;
        };

        defaultApp = pkgs.exyaru;

        packages = {
          exyaru = pkgs.exyaru;
        };

        defaultPackage = pkgs.exyaru;

        devShell = (pkgs.poetry2nix.mkPoetryEnv {
          projectDir = ./.;
          overrides = pkgs.poetry2nix.defaultPoetryOverrides.extend ( self: super: {
            uengine = super.uengine.overridePythonAttrs (
              old: {
                buildInputs = (old.buildInputs or [ ]) ++ [ self.poetry ];
              }
            );
          });
          editablePackageSources = {
            exyaru = ./.;
          };
        }).env.overrideAttrs (oldAttrs: {
          buildInputs = [ pkgs.poetry ];
        });
      }));
}
15:43:35

Show newer messages


Back to Room ListRoom Version: 6