From a562da37971e51200d49fb0251b2d0d6bbc6be4a Mon Sep 17 00:00:00 2001 From: Gleb Smirnov Date: Sat, 21 Dec 2024 15:45:29 +0300 Subject: [PATCH] build(nix): make build non-dev --- flake.nix | 7 +++++-- nix/mkPackageAttrs.nix | 44 ++++++++++++++++++++++++++++-------------- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/flake.nix b/flake.nix index a45523e..f5b36db 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ }; outputs = - inputs@{ flake-parts, pyproject-nix, ... }: + inputs@{ self, flake-parts, pyproject-nix, ... }: flake-parts.lib.mkFlake { inherit inputs; } { systems = [ "x86_64-linux" @@ -33,7 +33,10 @@ python = pkgs.python3.override { packageOverrides = import ./nix/mkPackageOverrides.nix { inherit pkgs; }; }; - packageAttrs = import ./nix/mkPackageAttrs.nix { inherit pkgs project python; }; + packageAttrs = import ./nix/mkPackageAttrs.nix { + inherit pkgs project python; + rev = self.rev or null; + }; in { packages = { diff --git a/nix/mkPackageAttrs.nix b/nix/mkPackageAttrs.nix index 66942b8..8f4c389 100644 --- a/nix/mkPackageAttrs.nix +++ b/nix/mkPackageAttrs.nix @@ -1,16 +1,30 @@ -{ pkgs, project, python }: -(project.renderers.buildPythonPackage { inherit python; }) // { - src = ./..; - postPatch = '' - substituteInPlace pyproject.toml \ - --replace-fail "cryptg-anyos" "cryptg" - ''; - pythonRelaxDeps = [ - "cryptg" - ]; - meta = { - license = pkgs.lib.licenses.mit; - homepage = "https://tgpy.tmat.me/"; - pythonImportsCheck = [ "tgpy" ]; +{ + pkgs, + project, + python, + rev, +}: +let + postPatch = + '' + substituteInPlace pyproject.toml \ + --replace-fail "cryptg-anyos" "cryptg" + '' + + pkgs.lib.optionalString (rev != null) '' + substituteInPlace tgpy/version.py \ + --replace-fail "COMMIT_HASH = None" "COMMIT_HASH = \"${rev}\"" + ''; + newAttrs = { + src = ./..; + inherit postPatch; + pythonRelaxDeps = [ + "cryptg" + ]; + meta = { + license = pkgs.lib.licenses.mit; + homepage = "https://tgpy.tmat.me/"; + pythonImportsCheck = [ "tgpy" ]; + }; }; -} +in +(project.renderers.buildPythonPackage { inherit python; }) // newAttrs