nix-exprs/templates/python-uv/flake.nix

109 lines
2.9 KiB
Nix

{
outputs =
inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
"x86_64-linux"
"aarch64-linux"
];
imports = [
inputs.devshell.flakeModule
inputs.git-hooks-nix.flakeModule
inputs.treefmt-nix.flakeModule
];
perSystem =
{
config,
pkgs,
lib,
...
}:
let
workspace = inputs.uv2nix.lib.workspace.loadWorkspace { workspaceRoot = ./.; };
overlay = workspace.mkPyprojectOverlay { sourcePreference = "wheel"; };
pyprojectOverrides = _final: _prev: { };
pythonSet =
(pkgs.callPackage inputs.pyproject-nix.build.packages {
python = pkgs.python311;
}).overrideScope
(lib.composeExtensions overlay pyprojectOverrides);
in
{
devshells.default = {
packages = [
(pythonSet.mkVirtualEnv "python-uv-env" workspace.deps.all)
pkgs.python311Packages.uv
config.treefmt.build.wrapper
];
env = [
(lib.nameValuePair "UV_PYTHON" "${lib.getExe pkgs.python311}")
(lib.nameValuePair "DEVSHELL_NO_MOTD" 1)
{
name = "PYTHONPATH";
unset = true;
}
];
devshell.startup.pre-commit-hook.text = config.pre-commit.installationScript;
};
treefmt = {
projectRootFile = "flake.nix";
programs = {
nixfmt.enable = true;
ruff-check.enable = true;
ruff-format.enable = true;
};
};
pre-commit.settings.hooks.treefmt = {
enable = true;
name = "treefmt";
entry = lib.getExe config.treefmt.build.wrapper;
pass_filenames = false;
};
};
};
inputs = {
# flake-parts
flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
};
# nixpkgs
nixpkgs.follows = "nixpkgs-unstable";
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
# flake modules
devshell = {
url = "github:numtide/devshell";
inputs.nixpkgs.follows = "nixpkgs";
};
git-hooks-nix = {
url = "github:cachix/git-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.nixpkgs-stable.follows = "nixpkgs";
};
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
# libraries
pyproject-nix = {
url = "github:nix-community/pyproject.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
uv2nix = {
url = "github:adisbladis/uv2nix";
inputs.pyproject-nix.follows = "pyproject-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
}