Skip to content

Commit 55477b5

Browse files
authored
add pyproject-nix overlay (#2802)
1 parent 156033f commit 55477b5

File tree

3 files changed

+47
-25
lines changed

3 files changed

+47
-25
lines changed

flake.nix

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,14 @@
7070
kevmOverlay = final: prev:
7171
let
7272
python = final."python${pythonVer}";
73+
kevm-pyk-pyproject = final.callPackage ./nix/kevm-pyk-pyproject {
74+
inherit uv2nix;
75+
};
7376
kevm-pyk = final.callPackage ./nix/kevm-pyk {
74-
inherit pyproject-nix pyproject-build-systems uv2nix python;
77+
inherit pyproject-nix pyproject-build-systems kevm-pyk-pyproject python;
78+
pyproject-overlays = [
79+
(k-framework.overlays.pyk-pyproject system)
80+
];
7581
};
7682
kevm = final.callPackage ./nix/kevm {
7783
inherit kevm-pyk python;
@@ -80,7 +86,7 @@
8086
kevm-test = final.callPackage ./nix/kevm/test.nix { };
8187
kevm-profile = final.callPackage ./package/nix/profile.nix { };
8288
in {
83-
inherit kevm kevm-test kevm-profile;
89+
inherit kevm kevm-test kevm-profile kevm-pyk-pyproject;
8490
};
8591
pkgs = import nixpkgs {
8692
inherit system;
@@ -146,7 +152,7 @@
146152
};
147153

148154
packages = rec {
149-
inherit (pkgs) kevm-pyk kevm kevm-test;
155+
inherit (pkgs) kevm-pyk kevm kevm-test kevm-pyk-pyproject;
150156
default = kevm;
151157
profile = pkgs.kevm-profile;
152158

@@ -160,8 +166,15 @@
160166
};
161167
};
162168
}) // {
163-
overlays.default = final: prev: {
164-
inherit (self.packages.${final.system}) kevm;
169+
overlays = {
170+
default = final: prev: {
171+
inherit (self.packages.${final.system}) kevm;
172+
};
173+
# this pyproject-nix overlay allows for overriding the python packages that are otherwise locked in `uv.lock`
174+
# by using this overlay in dependant nix flakes, you ensure that nix overrides also override the python package
175+
pyk-pyproject = system: final: prev: {
176+
inherit (self.packages.${system}.kevm-pyk-pyproject.lockFileOverlay final prev) kevm-pyk;
177+
};
165178
};
166179
};
167180
}

nix/kevm-pyk-pyproject/default.nix

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
lib,
3+
callPackage,
4+
5+
uv2nix,
6+
}:
7+
let
8+
src = callPackage ../kevm-source { };
9+
10+
# load a uv workspace from a workspace root
11+
workspace = uv2nix.lib.workspace.loadWorkspace {
12+
workspaceRoot = "${src}/kevm-pyk";
13+
};
14+
15+
# create overlay
16+
lockFileOverlay = workspace.mkPyprojectOverlay {
17+
# prefer "wheel" over "sdist" due to maintance overhead
18+
# there is no bundled set of overlays for "sdist" in uv2nix, in contrast to poetry2nix
19+
sourcePreference = "wheel";
20+
};
21+
in {
22+
inherit lockFileOverlay workspace;
23+
}

nix/kevm-pyk/default.nix

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,33 @@
11
{
22
lib,
33
callPackage,
4-
stdenvNoCC,
5-
6-
blockchain-k-plugin-src,
74

85
pyproject-nix,
96
pyproject-build-systems,
10-
uv2nix,
7+
kevm-pyk-pyproject,
8+
pyproject-overlays ? [ ],
119

1210
python
1311
}:
1412
let
13+
inherit (kevm-pyk-pyproject) lockFileOverlay workspace;
14+
1515
pyproject-util = callPackage pyproject-nix.build.util {};
1616
pyproject-packages = callPackage pyproject-nix.build.packages {
1717
inherit python;
1818
};
1919

20-
src = callPackage ../kevm-source { };
21-
22-
# load a uv workspace from a workspace root
23-
workspace = uv2nix.lib.workspace.loadWorkspace {
24-
workspaceRoot = "${src}/kevm-pyk";
25-
};
26-
27-
# create overlay
28-
lockFileOverlay = workspace.mkPyprojectOverlay {
29-
# prefer "wheel" over "sdist" due to maintance overhead
30-
# there is no bundled set of overlays for "sdist" in uv2nix, in contrast to poetry2nix
31-
sourcePreference = "wheel";
32-
};
33-
3420
buildSystemsOverlay = import ./build-systems-overlay.nix;
3521

3622
# construct package set
37-
pythonSet = pyproject-packages.overrideScope (lib.composeManyExtensions [
23+
pythonSet = pyproject-packages.overrideScope (lib.composeManyExtensions ([
3824
# make build tools available by default as these are not necessarily specified in python lock files
3925
pyproject-build-systems.overlays.default
4026
# include all packages from the python lock file
4127
lockFileOverlay
4228
# add build system overrides to certain python packages
4329
buildSystemsOverlay
44-
]);
30+
] ++ pyproject-overlays));
4531
in pyproject-util.mkApplication {
4632
# default dependancy group enables no optional dependencies and no dependency-groups
4733
venv = pythonSet.mkVirtualEnv "kevm-pyk-env" workspace.deps.default;

0 commit comments

Comments
 (0)