migrate to uv2nix
Some checks failed
Check flake.lock / Check health of `flake.lock` (pull_request) Successful in 7s
Check Nix formatting / Perform Nix format checks (pull_request) Successful in 2m36s
Check Nix flake / Build nix outputs (ubuntu-latest) (pull_request) Failing after 2m38s
Check Nix flake / Perform Nix flake checks (ubuntu-latest) (pull_request) Successful in 4m55s

Signed-off-by: ahuston-0 <aliceghuston@gmail.com>
This commit is contained in:
2025-03-18 18:11:42 -04:00
parent 4b7e2ef85c
commit ef9050523d
9 changed files with 454 additions and 395 deletions

122
flake.nix
View File

@ -22,10 +22,6 @@
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable-small";
poetry2nix = {
url = "github:nix-community/poetry2nix";
inputs.nixpkgs.follows = "nixpkgs";
};
pre-commit-hooks = {
url = "github:cachix/pre-commit-hooks.nix";
inputs = {
@ -34,6 +30,27 @@
# flake-compat.follows = "flake-compat";
};
};
pyproject-nix = {
url = "github:pyproject-nix/pyproject.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
uv2nix = {
url = "github:pyproject-nix/uv2nix";
inputs = {
nixpkgs.follows = "nixpkgs";
pyproject-nix.follows = "pyproject-nix";
};
};
pyproject-build-systems = {
url = "github:pyproject-nix/build-system-pkgs";
inputs = {
nixpkgs.follows = "nixpkgs";
pyproject-nix.follows = "pyproject-nix";
uv2nix.follows = "uv2nix";
};
};
};
outputs =
@ -41,39 +58,90 @@
self,
nixpkgs,
flake-utils,
poetry2nix,
uv2nix,
pyproject-nix,
pyproject-build-systems,
...
}@inputs:
flake-utils.lib.eachDefaultSystem (
system:
let
# see https://github.com/nix-community/poetry2nix/tree/master#api for more functions and examples.
pkgs = nixpkgs.legacyPackages.${system}.extend poetry2nix.overlays.default;
inherit (nixpkgs) lib;
overrides = pkgs.poetry2nix.overrides.withDefaults (
_final: _prev: {
# prefer binary wheels instead of source distributions for rust based dependencies
# avoids needing to build them from source. technically a security risk
#polars = prev.polars.override { preferWheel = true; };
#ruff = prev.ruff.override { preferWheel = true; };
#greenlet = prev.greenlet.override { preferWheel = true; };
#sqlalchemy = prev.sqlalchemy.override { preferWheel = true; };
}
);
# Load a uv workspace from a workspace root.
# Uv2nix treats all uv projects as workspace projects.
workspace = uv2nix.lib.workspace.loadWorkspace { workspaceRoot = ./.; };
poetryConfig = {
inherit overrides;
projectDir = self;
python = pkgs.python312;
# Create package overlay from workspace.
overlay = workspace.mkPyprojectOverlay {
# Prefer prebuilt binary wheels as a package source.
# Sdists are less likely to "just work" because of the metadata missing from uv.lock.
# Binary wheels are more likely to, but may still require overrides for library dependencies.
sourcePreference = "wheel";
#sourcePreference = "sdist";
# Optionally customise PEP 508 environment
# environ = {
# platform_release = "5.10.65";
# };
};
# Extend generated overlay with build fixups
#
# Uv2nix can only work with what it has, and uv.lock is missing essential metadata to perform some builds.
# This is an additional overlay implementing build fixups.
# See:
# - https://pyproject-nix.github.io/uv2nix/FAQ.html
pyprojectOverrides = _final: _prev: {
# Implement build fixups here.
# Note that uv2nix is _not_ using Nixpkgs buildPythonPackage.
# It's using https://pyproject-nix.github.io/pyproject.nix/build.html
};
# This example is only using x86_64-linux
pkgs = nixpkgs.legacyPackages.${system};
# Use Python 3.12 from nixpkgs
python = pkgs.python312;
# Construct package set
pythonSet =
# Use base package set from pyproject.nix builders
(pkgs.callPackage pyproject-nix.build.packages {
inherit python;
}).overrideScope
(
lib.composeManyExtensions [
pyproject-build-systems.overlays.default
overlay
pyprojectOverrides
]
);
uv-shell = import ./uv-shell.nix {
inherit
lib
pkgs
python
workspace
pythonSet
;
};
in
rec {
inherit pkgs;
packages = {
flupdt = pkgs.poetry2nix.mkPoetryApplication poetryConfig // {
develop = false;
# Package a virtual environment as our main application.
#
# Enable no optional dependencies for production build.
packages = rec {
flupdt = pythonSet.mkVirtualEnv "flupdt-env" workspace.deps.default;
default = flupdt;
};
# Make hello runnable with `nix run`
apps = {
default = {
type = "app";
program = "${packages.default}/bin/flupdt";
};
default = self.packages.${system}.flupdt;
};
formatter = pkgs.nixfmt-rfc-style;
@ -82,10 +150,10 @@
inherit
self
pkgs
poetryConfig
inputs
system
checks
uv-shell
;
};
checks = import ./checks.nix { inherit inputs system formatter; };