From f7474035ab5536abe69299fed6e124685ca9e3ef Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Mon, 5 Aug 2024 09:41:29 +0200 Subject: [PATCH 1/2] nix: parse dependencies from pyproject file --- flake.nix | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/flake.nix b/flake.nix index 2ec460a99..6a0d7482f 100644 --- a/flake.nix +++ b/flake.nix @@ -8,12 +8,19 @@ flake-utils.lib.eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; + pyproject = pkgs.lib.trivial.importTOML ./pyproject.toml; + # get a list of python packages by name + getPkgs = names: builtins.attrValues (pkgs.lib.attrsets.getAttrs names pkgs.python3Packages); + # extract the python dependencies from the pyprojec file, cut the version constraint + dependencies' = pkgs.lib.lists.concatMap (builtins.match "([^>=<]*).*") pyproject.project.dependencies; + # the package is called gpg on PyPI but gpgme in nixpkgs + dependencies = map (x: if x == "gpg" then "gpgme" else x) dependencies'; in { packages = { alot = pkgs.python3Packages.buildPythonApplication { name = "alot"; - version = "dev"; + version = pyproject.project.version + "-post"; src = self; pyproject = true; outputs = [ @@ -21,19 +28,8 @@ "doc" "man" ]; - build-system = with pkgs.python3Packages; [ - setuptools - setuptools-scm - ]; - dependencies = with pkgs.python3Packages; [ - configobj - gpgme - notmuch2 - python-magic - twisted - urwid - urwidtrees - ]; + build-system = getPkgs pyproject."build-system".requires; + dependencies = getPkgs dependencies; postPatch = '' substituteInPlace alot/settings/manager.py \ --replace /usr/share "$out/share" From 69bc1aad1f171653278322e1d291d27fddf5d3a8 Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Tue, 6 Aug 2024 21:23:16 +0200 Subject: [PATCH 2/2] nix: add comment about pyproject parsing --- flake.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 6a0d7482f..d487783da 100644 --- a/flake.nix +++ b/flake.nix @@ -8,8 +8,12 @@ flake-utils.lib.eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; + # we want to extract some metadata and especially the dependencies + # from the pyproject file, like this we do not have to maintain the + # list a second time pyproject = pkgs.lib.trivial.importTOML ./pyproject.toml; - # get a list of python packages by name + # get a list of python packages by name, used to get the nix packages + # for the dependency names from the pyproject file getPkgs = names: builtins.attrValues (pkgs.lib.attrsets.getAttrs names pkgs.python3Packages); # extract the python dependencies from the pyprojec file, cut the version constraint dependencies' = pkgs.lib.lists.concatMap (builtins.match "([^>=<]*).*") pyproject.project.dependencies;