!rWxyQqNqMUDLECdsIf:blad.is

Poetry2nix

303 Members
https://github.com/nix-community/poetry2nix55 Servers

Load older messages


SenderMessageTime
5 Nov 2023
@adis:blad.isadisbladisThe update process would literally be to download the upstream one and dump it03:49:46
@k900:0upti.meK900I kinda like that, but I'm also kinda worried about how to encode the fixups03:50:36
@k900:0upti.meK900Which we're going to need a lot of03:50:39
@k900:0upti.meK900I'm actually about to run myself into a much similar problem with KDE6 stuff03:51:00
@k900:0upti.meK900Because I really want to generate most of it from upstream metadata03:51:08
@k900:0upti.meK900But I'm not sure what a good API for adding fixups on top would be03:51:22
@adis:blad.isadisbladis

If you'd take the pyproject.nix approach with an abstract project representation and renderers you could do something like

 let 
  project = load ./pyproject.toml;
  attrs = render python3 project;
attrs // {
  buildInputs = attrs.buildInputs ++ [ pkgs.openssl ];
}
03:53:28
@adis:blad.isadisbladisOr something along those lines03:53:35
@adis:blad.isadisbladis *

If you'd take the pyproject.nix approach with an abstract project representation and renderers you could do something like

 let 
  project = load ./pyproject.toml;
  attrs = render python3 project;
in
python3.buildPythonPackage (attrs // {
  buildInputs = attrs.buildInputs ++ [ pkgs.openssl ];
})
03:54:05
@adis:blad.isadisbladis *

If you'd take the pyproject.nix approach with an abstract project representation and renderers you could do something like

 let 
  project = load ./pyproject.toml;
  attrs = render python3 project;
in
python3.buildPythonPackage (attrs // {
  buildInputs = attrs.buildInputs ++ [ pkgs.openssl ];
})
03:55:34
@adis:blad.isadisbladisBut I think that 90% of the time (just a number pulled out of thin air) you wouldn't need fixups03:58:07
6 Nov 2023
@adis:blad.isadisbladis

Thinking a bit out loud here about a possible interface for lock files:

{ lib, pkgs, poetry2nix, pyproject }:
let
  # Stub attrs, not yet implemented
  pdm = { };
  overlays = { };

  # Use project abstraction from pyproject.nix
  project = pyproject.project.loadPyproject {
    pyproject = lib.importTOML ./pyproject.toml;
  };

  # Python packages overlay
  overlay = let
    # Create an overlay from pdm.lock
    pdmPackages = pdm.mkOverlay {
      pyproject = lib.importTOML ./pyproject.toml;
      pdmLock = lib.importTOML ./pdm.lock;
    };
    # Pdm.lock is not having PEP-517 build systems locked, use overrides from poetry2nix
    pdmWithBuild = overlays.intersect pdmPackages poetry2nix.overlays.build-systems;
  # Only apply build system overrides to packages that actually need them (packages created by the overlay generator)
  in overlays.intersect pdmPackages poetry2nix.build-systems;

  # Create an overriden interpreter
  python = pkgs.python3.override {
    # Note the self argument.
    # It's important so the interpreter/set is internally consistent.
    self = python;
    packageOverrides = overlay;
  };

  # Render buildPythonPackage with our overriden interpreter
  attrs = pyproject.lib.renderers.buildPythonPackage { inherit python project; };

in python.pkgs.buildPythonPackage attrs
01:04:38
@adis:blad.isadisbladis *

Thinking a bit out loud here about a possible interface for lock files (cross post from #pyproject.nix:blad.is ):

{ lib, pkgs, poetry2nix, pyproject }:
let
  # Stub attrs, not yet implemented
  pdm = { };
  overlays = { };

  # Use project abstraction from pyproject.nix
  project = pyproject.project.loadPyproject {
    pyproject = lib.importTOML ./pyproject.toml;
  };

  # Python packages overlay
  overlay = let
    # Create an overlay from pdm.lock
    pdmPackages = pdm.mkOverlay {
      pyproject = lib.importTOML ./pyproject.toml;
      pdmLock = lib.importTOML ./pdm.lock;
    };
    # Pdm.lock is not having PEP-517 build systems locked, use overrides from poetry2nix
    pdmWithBuild = overlays.intersect pdmPackages poetry2nix.overlays.build-systems;
  # Only apply build system overrides to packages that actually need them (packages created by the overlay generator)
  in overlays.intersect pdmPackages poetry2nix.build-systems;

  # Create an overriden interpreter
  python = pkgs.python3.override {
    # Note the self argument.
    # It's important so the interpreter/set is internally consistent.
    self = python;
    packageOverrides = overlay;
  };

  # Render buildPythonPackage with our overriden interpreter
  attrs = pyproject.lib.renderers.buildPythonPackage { inherit python project; };

in python.pkgs.buildPythonPackage attrs
01:05:06
@adis:blad.isadisbladis cc K900 ⚡️ 01:05:19
@adis:blad.isadisbladis * cc K900 ⚡️ cpcloud etc 01:21:10
@adis:blad.isadisbladisNot exactly sure which project would implement what01:21:14
@adis:blad.isadisbladis *

Thinking a bit out loud here about a possible interface for lock files (cross post from #pyproject.nix:blad.is ):

{ lib, pkgs, poetry2nix, pyproject }:
let
  # Stub attrs, not yet implemented
  pdm = { };
  overlays = { };

  # Use project abstraction from pyproject.nix
  project = pyproject.project.loadPyproject {
    pyproject = lib.importTOML ./pyproject.toml;
  };

  # Python packages overlay
  overlay = let
    # Create an overlay from pdm.lock
    pdmPackages = pdm.mkOverlay {
      pyproject = lib.importTOML ./pyproject.toml;
      pdmLock = lib.importTOML ./pdm.lock;
    };
    # Pdm.lock does not have PEP-517 build systems locked, use overrides from poetry2nix
    pdmWithBuild = overlays.intersect pdmPackages poetry2nix.overlays.build-systems;
  # Only apply build system overrides to packages that actually need them (packages created by the overlay generator)
  in overlays.intersect pdmPackages poetry2nix.build-systems;

  # Create an overriden interpreter
  python = pkgs.python3.override {
    # Note the self argument.
    # It's important so the interpreter/set is internally consistent.
    self = python;
    packageOverrides = overlay;
  };

  # Render buildPythonPackage with our overriden interpreter
  attrs = pyproject.lib.renderers.buildPythonPackage { inherit python project; };

in python.pkgs.buildPythonPackage attrs
03:52:30
@adis:blad.isadisbladis

The same idea, but a bit more formed:

{ lib, pkgs, poetry2nix, pyproject }:
let
  # Stub attrs, not yet implemented
  pdm = {
    mkOverlay = { ... }: throw "Not implemented";
  };
  overlays = {
    # Return overlay `a` with `b` applied, but only with intersecting keys.
    # This is useful when filtering
    intersect = a: b: throw "Not implemented";

    # Return overlay filtered by predicate
    filter = pred: overlay: throw "Not implemented";
  };

  # Use project abstraction from pyproject.nix
  project = pyproject.project.loadPyproject {
    pyproject = lib.importTOML ./pyproject.toml;
  };

  # Python packages overlay
  overlay = let
    # Create an overlay from pdm.lock
    pdmPackages = pdm.mkOverlay {
      pyproject = lib.importTOML ./pyproject.toml;
      pdmLock = lib.importTOML ./pdm.lock;
    };

    # Use nixpkgs definitions whenever possible, only overlay missing packages
    onlyPdm = overlays.filter (pname: overriden: ! lib.hasAttr pname pkgs.python3.pkgs) pdmPackages;

    # Pdm.lock does not have PEP-517 build systems locked, use overrides from poetry2nix
    pdmWithBuild = overlays.intersect onlyPdm poetry2nix.overlays.build-systems;
  in pdmWithBuild;

  # Create an overriden interpreter
  python = pkgs.python3.override {
    # Note the self argument.
    # It's important so the interpreter/set is internally consistent.
    self = python;
    packageOverrides = overlay;
  };

  # Render buildPythonPackage with our overriden interpreter
  attrs = pyproject.lib.renderers.buildPythonPackage { inherit python project; };

in python.pkgs.buildPythonPackage attrs
04:03:58
@adis:blad.isadisbladis *

The same idea, but a bit more formed:

{ lib, pkgs, poetry2nix, pyproject }:
let
  # Stub attrs, not yet implemented
  pdm = {
    mkOverlay = { ... }: throw "Not implemented";
  };
  overlays = {
    # Return overlay `a` with `b` applied, but only with intersecting keys.
    intersect = a: b: throw "Not implemented";

    # Return overlay filtered by predicate
    filter = pred: overlay: throw "Not implemented";
  };

  # Use project abstraction from pyproject.nix
  project = pyproject.project.loadPyproject {
    pyproject = lib.importTOML ./pyproject.toml;
  };

  # Python packages overlay
  overlay = let
    # Create an overlay from pdm.lock
    pdmPackages = pdm.mkOverlay {
      pyproject = lib.importTOML ./pyproject.toml;
      pdmLock = lib.importTOML ./pdm.lock;
    };

    # Use nixpkgs definitions whenever possible, only overlay missing packages
    onlyPdm = overlays.filter (pname: overriden: ! lib.hasAttr pname pkgs.python3.pkgs) pdmPackages;

    # Pdm.lock does not have PEP-517 build systems locked, use overrides from poetry2nix
    pdmWithBuild = overlays.intersect onlyPdm poetry2nix.overlays.build-systems;
  in pdmWithBuild;

  # Create an overriden interpreter
  python = pkgs.python3.override {
    # Note the self argument.
    # It's important so the interpreter/set is internally consistent.
    self = python;
    packageOverrides = overlay;
  };

  # Render buildPythonPackage with our overriden interpreter
  attrs = pyproject.lib.renderers.buildPythonPackage { inherit python project; };

in python.pkgs.buildPythonPackage attrs
04:25:06
@adis:blad.isadisbladisNo takers? :P08:16:43
@adis:blad.isadisbladisI really want some input on this before I go nuts and implement something like it08:58:52
@k900:0upti.meK900Looks pretty good to me but I can't brain right now08:59:28
@zeratax:dmnd.shzeratax (any/all)
{
  inputs.flake-utils.url = "github:numtide/flake-utils";
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
  inputs.poetry2nix = {
    url = "github:sciyoshi/poetry2nix/master";
    inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = { self, nixpkgs, flake-utils, poetry2nix }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        inherit (poetry2nix.legacyPackages.${system}) mkPoetryEnv;

        projectPath =  builtins.path { path = ./.; name = "shark3d-deployment"; };
        pkgs = nixpkgs.legacyPackages.${system};
        deployment = mkPoetryEnv {
          python = pkgs.python311;
          projectDir = projectPath;
          editablePackageSources = {
            deployment = projectPath;
          };
        };
      in
      {
        devShells.default = deployment.env.overrideAttrs (oldAttrs: {
            buildInputs = [ pkgs.kubectl pkgs.pulumi-bin ];
        });
      });
}
12:53:31
@zeratax:dmnd.shzeratax (any/all) *
{
  inputs.flake-utils.url = "github:numtide/flake-utils";
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
  inputs.poetry2nix = {
    url = "github:sciyoshi/poetry2nix/master";
    inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = { self, nixpkgs, flake-utils, poetry2nix }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        inherit (poetry2nix.legacyPackages.${system}) mkPoetryEnv;

        projectPath =  builtins.path { path = ./.; name = "shark3d-deployment"; };
        pkgs = nixpkgs.legacyPackages.${system};
        deployment = mkPoetryEnv {
          python = pkgs.python311;
          projectDir = projectPath;
          editablePackageSources = {
            deployment = projectPath;
          };
        };
      in
      {
        devShells.default = deployment.env.overrideAttrs (oldAttrs: {
            buildInputs = [ pkgs.kubectl pkgs.pulumi-bin ];
        });
      });
}
nix develop
warning: Git tree '/home/jonaa/git/deployment' is dirty
error: list index 2 is out of bounds

       at /nix/store/dqxnzhmh5xq79508f9h6rg11jqy9nnmv-source/shell-scripts.nix:10:12:

            9|       module = elem 0;
           10|       fn = elem 2;
             |            ^
           11|     in
(use '--show-trace' to show detailed location information)

not sure what this means

12:54:54
@zeratax:dmnd.shzeratax (any/all) *
{
  inputs.flake-utils.url = "github:numtide/flake-utils";
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
  inputs.poetry2nix = {
    url = "github:sciyoshi/poetry2nix/master";
    inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = { self, nixpkgs, flake-utils, poetry2nix }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        inherit (poetry2nix.legacyPackages.${system}) mkPoetryEnv;

        projectPath =  builtins.path { path = ./.; name = "shark3d-deployment"; };
        pkgs = nixpkgs.legacyPackages.${system};
        deployment = mkPoetryEnv {
          python = pkgs.python311;
          projectDir = projectPath;
          editablePackageSources = {
            deployment = projectPath;
          };
        };
      in
      {
        devShells.default = deployment.env.overrideAttrs (oldAttrs: {
            buildInputs = [ pkgs.kubectl pkgs.pulumi-bin ];
        });
      });
}
nix develop
warning: Git tree '/home/jonaa/git/deployment' is dirty
error: list index 2 is out of bounds

       at /nix/store/dqxnzhmh5xq79508f9h6rg11jqy9nnmv-source/shell-scripts.nix:10:12:

            9|       module = elem 0;
           10|       fn = elem 2;
             |            ^
           11|     in
(use '--show-trace' to show detailed location information)

not sure what this means

12:57:20
@k900:0upti.meK900Please use poetry2nix upstream now12:58:24
@k900:0upti.meK900Actually why are you even using a poetry2nix fork with 23.0512:58:53
@zeratax:dmnd.shzeratax (any/all)oh wow idk why i used a fork13:00:32
@zeratax:dmnd.shzeratax (any/all)yeah sorry about that. idk where i copied that from >.>13:11:18
@zeratax:dmnd.shzeratax (any/all) * yeah sorry about that. idk where i copied that from >.> but thank you!13:11:26

Show newer messages


Back to Room ListRoom Version: 6