Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
WeetHet committed Dec 20, 2024
1 parent 5fcd14c commit 938f92c
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 235 deletions.
113 changes: 10 additions & 103 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

126 changes: 47 additions & 79 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,94 +4,62 @@
inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
poetry2nix = {
url = "github:nix-community/poetry2nix";
pyproject-nix = {
url = "github:pyproject-nix/pyproject.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = inputs@{ nixpkgs, flake-parts, ... }:
let
readMetadata = { lib }: (
outputs =
inputs@{ flake-parts, pyproject-nix, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
"x86_64-darwin"
];

perSystem =
{ config, pkgs, ... }:
let
pyproject = builtins.fromTOML (
builtins.readFile ./pyproject.toml
);
project = pyproject-nix.lib.project.loadPyproject {
projectRoot = ./.;
};
python = pkgs.python3.override {
packageOverrides = import ./nix/mkPackageOverrides.nix { inherit pkgs; };
};
packageAttrs = project.renderers.buildPythonPackage { inherit python; };
in
(with pyproject.tool.poetry; {
inherit description;
homepage = documentation;
license = lib.meta.getLicenseFromSpdxId license;
})
);
in
flake-parts.lib.mkFlake { inherit inputs; } rec {
flake = rec {
lib.mkPackageRequirements =
{ overrides, requirements }:
overrides.extend (final: prev:
builtins.mapAttrs (package: reqs:
(builtins.getAttr package prev).overridePythonAttrs (old: {
buildInputs = (old.buildInputs or [ ]) ++ (builtins.map (pkg: prev.${pkg}) reqs);
})
) requirements
);
lib.mkTgpy =
{ system ? null
, pkgs ? import nixpkgs { inherit system; }
, poetry2nix ? inputs.poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }
}: poetry2nix.mkPoetryApplication {
projectDir = ./.;
preferWheels = false;
meta = readMetadata { lib = pkgs.lib; };
overrides = lib.mkPackageRequirements {
overrides = poetry2nix.defaultPoetryOverrides.extend (self: super: {
cryptg-anyos = super.cryptg-anyos.override {
preferWheel = true;
{
packages = {
tgpy = python.pkgs.buildPythonPackage (
packageAttrs
// {
meta = with pkgs.lib; {
description = "Run Python code right in your Telegram messages";
homepage = "https://tgpy.tmat.me/";
license = licenses.mit;
mainProgram = "tgpy";
platforms = platforms.all;
pythonImportsCheck = [ "tgpy" ];
};
nh3 = import ./nix/nh3overrides.nix { inherit self super pkgs; };
});
requirements = {
telethon-v1-24 = [ "setuptools" ];
pipreqs = [ "setuptools" ];
python-semantic-release = [ "setuptools" ];
};
};
}
);
default = config.packages.tgpy;
};
};

systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ];
perSystem = { self', pkgs, ... }: {
packages = {
tgpy = flake.lib.mkTgpy {
inherit pkgs;
};
default = self'.packages.tgpy;
};

devShells.default =
let
poetry2nix = inputs.poetry2nix.lib.mkPoetry2Nix { inherit pkgs; };
in
(poetry2nix.mkPoetryEnv {
projectDir = ./.;
preferWheels = true;
groups = [ "dev" ];
}).overrideAttrs (old: {
nativeBuildInputs = with pkgs; [
poetry
python3Packages.python-lsp-server
] ++ (with pkgs.python3Packages; [
mkdocs
mkdocs-material
mkdocs-redirects
mkdocs-git-revision-date-localized-plugin
cairosvg
pillow
]);
});
devShells.default =
let
pythonEnv = python.withPackages (project.renderers.withPackages { inherit python; });
in
pkgs.mkShell {
packages = [
pythonEnv
];
};

formatter = pkgs.nixpkgs-fmt;
};
formatter = pkgs.nixfmt-rfc-style;
};
};
}
24 changes: 24 additions & 0 deletions nix/mkPackageOverrides.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{ pkgs }:
self: super: {
telethon-v1-24 = super.telethon.overridePythonAttrs (old: rec {
version = "1.24.18";
src = pkgs.fetchPypi {
pname = "Telethon-v1.24";
inherit version;
hash = "sha256-rVgunqMHpOLjRhIZ7RfugTrrv136YtTlqa9CvWOyElY=";
};
doCheck = false;
});
cryptg-anyos = super.cryptg.overridePythonAttrs (old: rec {
version = "0.4.1";
src = super.fetchPypi {
pname = "cryptg-anyos";
inherit version;
hash = "sha256-pXY0CfdZRDjgID78STTDrvm1wUj4z1AooUBtrSG09Qo=";
};
cargoDeps = pkgs.rustPlatform.fetchCargoTarball {
inherit src;
hash = "sha256-AqSVFOB9Lfvk9h3GtoYlEOXBEt7YZYLhCDNKM9upQ2U=";
};
});
}
17 changes: 0 additions & 17 deletions nix/nh3overrides.nix

This file was deleted.

Loading

0 comments on commit 938f92c

Please sign in to comment.