Skip to content

Commit 09c4e43

Browse files
committed
build: switch to uv2nix
1 parent 4b54eee commit 09c4e43

File tree

2 files changed

+138
-35
lines changed

2 files changed

+138
-35
lines changed

flake.lock

Lines changed: 52 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 86 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# TODO: use uv2nix
21
{
32
inputs = {
43
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
@@ -7,26 +6,39 @@
76
inputs.nixpkgs.follows = "nixpkgs";
87
};
98

9+
uv = {
10+
url = "github:pyproject-nix/uv2nix";
11+
inputs = {
12+
nixpkgs.follows = "nixpkgs";
13+
pyproject-nix.follows = "pyproject";
14+
};
15+
};
16+
17+
build-systems = {
18+
url = "github:pyproject-nix/build-system-pkgs";
19+
inputs = {
20+
uv2nix.follows = "uv";
21+
nixpkgs.follows = "nixpkgs";
22+
pyproject-nix.follows = "pyproject";
23+
};
24+
};
25+
1026
pyproject = {
1127
url = "github:pyproject-nix/pyproject.nix";
1228
inputs.nixpkgs.follows = "nixpkgs";
1329
};
1430
};
1531

1632
outputs = {
33+
uv,
1734
self,
1835
hooks,
1936
nixpkgs,
2037
pyproject,
38+
build-systems,
2139
...
2240
}: let
23-
forAllSystems = function:
24-
nixpkgs.lib.genAttrs [
25-
"x86_64-linux"
26-
"aarch64-linux"
27-
"x86_64-darwin"
28-
"aarch64-darwin"
29-
] (system: function system nixpkgs.legacyPackages.${system});
41+
inherit (nixpkgs) lib;
3042

3143
getPythonVersion = let
3244
val = builtins.getEnv "PYTHON_VERSION";
@@ -37,52 +49,92 @@
3749
in
3850
builtins.replaceStrings ["."] [""] result;
3951

40-
project = pyproject.lib.project.loadPyproject {projectRoot = ./.;};
52+
workspace = uv.lib.workspace.loadWorkspace {workspaceRoot = ./.;};
53+
overlay = workspace.mkPyprojectOverlay {sourcePreference = "wheel";};
54+
55+
forAllSystems = f:
56+
lib.genAttrs [
57+
"x86_64-linux"
58+
"aarch64-linux"
59+
"x86_64-darwin"
60+
"aarch64-darwin"
61+
] (system:
62+
f rec {
63+
inherit system;
64+
65+
pkgs = nixpkgs.legacyPackages.${system};
66+
python = pkgs."python${getPythonVersion}";
67+
68+
pythonSet =
69+
(pkgs.callPackage pyproject.build.packages {inherit python;}).overrideScope (
70+
lib.composeManyExtensions [
71+
build-systems.overlays.default
72+
overlay
73+
]
74+
);
75+
});
4176
in {
4277
devShells =
43-
forAllSystems (system: pkgs: let
44-
python = pkgs."python${getPythonVersion}";
45-
arg =
46-
project.renderers.withPackages {
47-
inherit python project;
48-
groups = ["test"];
49-
};
50-
51-
pyenv = python.withPackages arg;
78+
forAllSystems ({
79+
pkgs,
80+
system,
81+
python,
82+
...
83+
}: let
5284
check = self.checks.${system}.pre-commit-check;
5385
in {
86+
# note: impure, editable overlays in uv2nix are unstable
5487
default =
5588
pkgs.mkShell {
56-
inherit (check) shellHook;
57-
58-
packages =
59-
check.enabledPackages
60-
++ [
61-
pyenv
62-
pkgs.uv
63-
];
89+
packages = check.enabledPackages ++ [python pkgs.uv];
90+
env =
91+
{
92+
UV_PYTHON_DOWNLOADS = "never";
93+
UV_PYTHON = python.interpreter;
94+
}
95+
// lib.optionalAttrs pkgs.stdenv.isLinux {
96+
LD_LIBRARY_PATH = lib.makeLibraryPath pkgs.pythonManylinuxPackages.manylinux1;
97+
};
6498
};
99+
100+
shellHook =
101+
''
102+
unset PYTHONPATH
103+
''
104+
++ check.shellHook;
65105
});
66106

67107
packages =
68-
forAllSystems (system: pkgs: let
69-
python = pkgs."python${getPythonVersion}";
70-
attrs = project.renderers.buildPythonPackage {inherit python project;};
71-
in rec {
72-
default = python.pkgs.buildPythonPackage attrs;
73-
wheel = default.dist;
108+
forAllSystems ({pythonSet, ...}: {
109+
default = pythonSet.mkVirtualEnv "proselint-env" workspace.deps.default;
110+
111+
wheel =
112+
pythonSet.proselint.override {
113+
pyprojectHook = pythonSet.pyprojectDistHook;
114+
};
115+
116+
sdist =
117+
(pythonSet.proselint.override {
118+
pyprojectHook = pythonSet.pyprojectDistHook;
119+
}).overrideAttrs (old: {
120+
env.uvBuildType = "sdist";
121+
});
74122
});
75123

76124
apps =
77-
forAllSystems (system: _: {
125+
forAllSystems ({system, ...}: {
78126
default = {
79127
type = "app";
80128
program = "${self.packages.${system}.default}/bin/proselint";
81129
};
82130
});
83131

84132
checks =
85-
forAllSystems (system: pkgs: {
133+
forAllSystems ({
134+
system,
135+
pkgs,
136+
...
137+
}: {
86138
pre-commit-check =
87139
hooks.lib.${system}.run {
88140
src = ./.;

0 commit comments

Comments
 (0)