stock-script/flake.nix
2024-10-31 15:56:20 +01:00

66 lines
1.9 KiB
Nix

{
description = "A basic flake using pyproject.toml project metadata";
inputs = {
pyproject-nix = {
url = "github:nix-community/pyproject.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{ nixpkgs, pyproject-nix, ... }:
let
inherit (nixpkgs) lib;
project = pyproject-nix.lib.project.loadPyproject {
# Read & unmarshal pyproject.toml relative to this project root.
# projectRoot is also used to set `src` for renderers such as buildPythonPackage.
projectRoot = ./.;
};
# This example is only using x86_64-linux
pkgs = nixpkgs.legacyPackages.x86_64-linux;
python = pkgs.python3;
in
{
devShells.x86_64-linux.default =
let
# Returns a function that can be passed to `python.withPackages`
arg = project.renderers.withPackages { inherit python; };
# Returns a wrapped environment (virtualenv like) with all our packages
pythonEnv = python.withPackages arg;
in
# Create a devShell like normal.
pkgs.mkShell {
packages = [
pythonEnv
pkgs.python311Packages.python-lsp-server
pkgs.python311Packages.python-lsp-ruff
pkgs.python311Packages.pylsp-mypy
pkgs.python311Packages.mypy
pkgs.python311Packages.isort
];
};
# Build our package using `buildPythonPackage
packages.x86_64-linux.default =
let
# Returns an attribute set that can be passed to `buildPythonPackage`.
attrs = project.renderers.buildPythonPackage { inherit python; };
in
# Pass attributes to buildPythonPackage.
# Here is a good spot to add on any missing or custom attributes.
python.pkgs.buildPythonPackage (
attrs
// {
env.CUSTOM_ENVVAR = "hello";
}
);
};
}