Skip to content

Commit 46ae51f

Browse files
authored
Introduce pyproject-nix overlay in nix flake (#4862)
In the past, when we were using poetry2nix, we used additional overlays in nix to ensure that nix flake overrides, e.g. `nix build --override-input kevm/k-framework v1.0.0`, do not only override the nix flake but also the python package that was locked in `poetry.lock`. With the migration to `uv2nix`, this overlay was removed, causing confusion and overhead when wanting to override python code using nix flake overrides. This PR re-introduces these overlays that can be used in dependent nix flakes to re-establish this behaviour. Due to `uv2nix` using the newer nix python packaging tooling `pyproject-nix`, this code adds more complexity in comparison to `poetry2nix`, though it nonetheless achieves the same result. There will be similar PRs in other repositories introducing and using these pyproject-nix overlays.
1 parent e5d9e82 commit 46ae51f

3 files changed

Lines changed: 49 additions & 27 deletions

File tree

flake.nix

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,16 @@
3939
uv = uv2nix.packages.${final.system}.uv-bin;
4040
};
4141
pykOverlay = final: prev: rec {
42+
pyk-pyproject = final.callPackage ./nix/pyk-pyproject {
43+
inherit uv2nix;
44+
};
45+
4246
pyk-python310 = final.callPackage ./nix/pyk {
43-
inherit pyproject-nix pyproject-build-systems uv2nix;
47+
inherit pyproject-nix pyproject-build-systems pyk-pyproject;
4448
python = final."python310";
4549
};
4650
pyk-python311 = final.callPackage ./nix/pyk {
47-
inherit pyproject-nix pyproject-build-systems uv2nix;
51+
inherit pyproject-nix pyproject-build-systems pyk-pyproject;
4852
python = final."python311";
4953
};
5054
pyk = pyk-python310;
@@ -204,7 +208,7 @@
204208
pkgs.lib.removeSuffix "\n" (builtins.readFile ./package/version);
205209

206210
packages = rec {
207-
inherit (pkgs) k k-lock pyk pyk-python310 pyk-python311 maven;
211+
inherit (pkgs) k k-lock pyk pyk-python310 pyk-python311 pyk-pyproject maven;
208212

209213
check-submodules = rv-nix-tools.lib.check-submodules pkgs {
210214
inherit llvm-backend haskell-backend;
@@ -248,6 +252,7 @@
248252
substituteInPlace tests/regression-new/append/kparse-twice \
249253
--replace '"$(dirname "$0")/../../../bin/kparse"' '"${k}/bin/kparse"'
250254
'';
255+
251256
buildFlags = [
252257
"K_BIN=${k}/bin"
253258
"KLLVMLIB=${k}/lib/kllvm"
@@ -295,6 +300,11 @@
295300
overlays.default = final: prev: {
296301
inherit (self.packages.${final.system}) k;
297302
};
303+
# this pyproject-nix overlay allows for overriding the python packages that are otherwise locked in `uv.lock`
304+
# by using this overlay in dependant nix flakes, you ensure that nix overrides also override the python package
305+
overlays.pyk-pyproject = system: final: prev: {
306+
inherit (self.packages.${system}.pyk-pyproject.lockFileOverlay final prev) kframework;
307+
};
298308

299309
# deprecated flake overlay output, please use `overlays.default` or `overlays.pyk` instead
300310
overlay = nixpkgs.lib.composeManyExtensions allOverlays;

nix/pyk-pyproject/default.nix

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
lib,
3+
callPackage,
4+
nix-gitignore,
5+
6+
uv2nix,
7+
}:
8+
let
9+
# load a uv workspace from a workspace root
10+
workspace = uv2nix.lib.workspace.loadWorkspace {
11+
workspaceRoot = lib.cleanSource (nix-gitignore.gitignoreSourcePure [
12+
../../.gitignore
13+
".github/"
14+
"result*"
15+
"/deps/"
16+
# do not include submodule directories that might be initilized empty or non-existent
17+
] ../../pyk/.
18+
);
19+
};
20+
21+
# create overlay
22+
lockFileOverlay = workspace.mkPyprojectOverlay {
23+
# prefer "wheel" over "sdist" due to maintance overhead
24+
# there is no bundled set of overlays for "sdist" in uv2nix, in contrast to poetry2nix
25+
sourcePreference = "wheel";
26+
};
27+
in {
28+
inherit lockFileOverlay workspace;
29+
}

nix/pyk/default.nix

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,21 @@
11
{
22
lib,
33
callPackage,
4-
nix-gitignore,
54

6-
pyproject-nix,
75
pyproject-build-systems,
8-
uv2nix,
6+
pyproject-nix,
7+
pyk-pyproject,
98

10-
python
9+
python,
1110
}:
1211
let
12+
inherit (pyk-pyproject) lockFileOverlay workspace;
13+
1314
pyproject-util = callPackage pyproject-nix.build.util {};
1415
pyproject-packages = callPackage pyproject-nix.build.packages {
1516
inherit python;
1617
};
1718

18-
# load a uv workspace from a workspace root
19-
workspace = uv2nix.lib.workspace.loadWorkspace {
20-
workspaceRoot = lib.cleanSource (nix-gitignore.gitignoreSourcePure [
21-
../../.gitignore
22-
".github/"
23-
"result*"
24-
"/deps/"
25-
# do not include submodule directories that might be initilized empty or non-existent
26-
] ../../pyk/.
27-
);
28-
};
29-
30-
# create overlay
31-
lockFileOverlay = workspace.mkPyprojectOverlay {
32-
# prefer "wheel" over "sdist" due to maintance overhead
33-
# there is no bundled set of overlays for "sdist" in uv2nix, in contrast to poetry2nix
34-
sourcePreference = "wheel";
35-
};
36-
3719
buildSystemsOverlay = import ./build-systems-overlay.nix;
3820

3921
# construct package set
@@ -45,7 +27,8 @@ let
4527
# add build system overrides to certain python packages
4628
buildSystemsOverlay
4729
]);
48-
in pyproject-util.mkApplication {
30+
in
31+
pyproject-util.mkApplication {
4932
# default dependancy group enables no optional dependencies and no dependency-groups
5033
venv = pythonSet.mkVirtualEnv "pyk-env" workspace.deps.default;
5134
package = pythonSet.kframework;

0 commit comments

Comments
 (0)