Skip to content

Commit

Permalink
nix: use flake-parts, add meta
Browse files Browse the repository at this point in the history
  • Loading branch information
WeetHet committed Sep 15, 2024
1 parent 710184b commit a4b13c3
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 60 deletions.
55 changes: 26 additions & 29 deletions flake.lock

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

72 changes: 41 additions & 31 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,52 +1,62 @@
{
description = "Run Python code snippets within your Telegram messages";
description = "Description for the project";

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

outputs =
{ self
, nixpkgs
, flake-utils
, ...
}@inputs:
{
lib.mkTgpy =
{ system ? null
, pkgs ? import nixpkgs { inherit system; }
, poetry2nix ? inputs.poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }
}: poetry2nix.mkPoetryApplication {
projectDir = ./.;
preferWheels = true;
};
} //
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs { inherit system; };
poetry2nix = inputs.poetry2nix.lib.mkPoetry2Nix { inherit pkgs; };
in
{
packages = rec {
tgpy = self.lib.mkTgpy { inherit system; };
default = tgpy;
outputs = inputs@{ nixpkgs, flake-parts, ... }:
let
readMetadata = { lib }: (
let pyproject = builtins.fromTOML (
builtins.readFile ./pyproject.toml
); in
(with pyproject.tool.poetry; {
inherit description;
homepage = documentation;
license = lib.meta.getLicenseFromSpdxId license;
})
);
in
flake-parts.lib.mkFlake { inherit inputs; } rec {
flake = {
lib.mkTgpy =
{ system ? null
, pkgs ? import nixpkgs { inherit system; }
, poetry2nix ? inputs.poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }
}: poetry2nix.mkPoetryApplication {
projectDir = ./.;
preferWheels = true;
meta = readMetadata { lib = pkgs.lib; };
};
};

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

devShells.default = (poetry2nix.mkPoetryEnv {
devShells.default = ((inputs'.poetry2nix.lib.mkPoetry2nix { inherit pkgs; }).mkPoetryEnv {
projectDir = ./.;
preferWheels = true;
groups = [ "dev" "guide" ];
}).overrideAttrs (old: {
nativeBuildInputs = with pkgs; [
poetry
python3Packages.python-lsp-server
];
});
}
);

formatter = pkgs.nixpkgs-fmt;
};
};
}

0 comments on commit a4b13c3

Please sign in to comment.