Skip to content

Commit 0054ada

Browse files
juliankunersjbertholdtothtamas28
authored
Add pyproject-nix overlay in nix derivation (#724)
Previously, when RV nix derivations were using `poetry2nix`, overriding a nix input in nix was also overriding the python code and resources used in `poetry2nix`. This allowed for easy overrides of python and K semantics changes by utilizing nix overrides. With the migration to `uv` and `uv2nix`, this was behavior was removed due to the respective code not documenting it's purpose. In addition, due to `uv2nix` relying on state-of-the-art python nix packaging tooling `pyproject-nix` instead of `nixpkgs`, ensuring identical override behaviour requires more nix logic. This PR re-introduces this kind of behaviour with `uv2nix`, though it depends on newly introduced overlays in the k nix flake. ### Example You can override k by running: `kup install kmir --override k-framework ~/path/to/local-k-checkout`. This will now also build kmir with the python and K code in `~/path/to/local-k-checkout`. --------- Co-authored-by: Jost Berthold <jost.berthold@gmail.com> Co-authored-by: Tamás Tóth <tothtamas28@users.noreply.github.com>
1 parent 9c279b8 commit 0054ada

3 files changed

Lines changed: 54 additions & 24 deletions

File tree

flake.nix

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,22 @@
7373
final: prev:
7474
let
7575
rev = self.rev or null;
76+
kmir-pyk-pyproject = final.callPackage ./nix/kmir-pyk-pyproject { inherit uv2nix; };
7677
kmir-pyk = final.callPackage ./nix/kmir-pyk {
77-
inherit pyproject-nix pyproject-build-systems uv2nix;
78+
inherit pyproject-nix pyproject-build-systems kmir-pyk-pyproject;
7879
python = final."python${pythonVer}";
80+
pyproject-overlays = [ (k-framework.overlays.pyk-pyproject system) ];
7981
};
8082
kmir = final.callPackage ./nix/kmir { inherit kmir-pyk rev; };
8183
kmir-package-test = final.callPackage ./nix/test/package.nix { inherit rev; };
8284
in
8385
{
84-
inherit kmir-pyk kmir kmir-package-test;
86+
inherit
87+
kmir-pyk
88+
kmir
89+
kmir-package-test
90+
kmir-pyk-pyproject
91+
;
8592
};
8693
pkgs = import nixpkgs {
8794
inherit system;
@@ -137,5 +144,12 @@
137144
)
138145
// {
139146
overlays.default = final: prev: { inherit (self.packages.${final.system}) kmir; };
147+
pyprojectOverlays = {
148+
# this pyproject-nix overlay allows for overriding the python packages that are otherwise locked in `uv.lock`
149+
# by using this overlay in dependant nix flakes, you ensure that nix overrides also override the python package
150+
pyk-pyproject = system: final: prev: {
151+
inherit (self.packages.${system}.kmir-pyk-pyproject.lockFileOverlay final prev) kmir-pyk;
152+
};
153+
};
140154
};
141155
}

nix/kmir-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+
nix-gitignore,
5+
6+
uv2nix,
7+
}:
8+
let
9+
src = callPackage ../kmir-source { };
10+
11+
# load a uv workspace from a workspace root
12+
workspace = uv2nix.lib.workspace.loadWorkspace { workspaceRoot = "${src}/kmir"; };
13+
14+
# create overlay
15+
lockFileOverlay = workspace.mkPyprojectOverlay {
16+
# prefer "wheel" over "sdist" due to maintance overhead
17+
# there is no bundled set of overlays for "sdist" in uv2nix, in contrast to poetry2nix
18+
sourcePreference = "wheel";
19+
};
20+
in
21+
{
22+
inherit lockFileOverlay workspace;
23+
}

nix/kmir-pyk/default.nix

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,35 @@
11
{
22
lib,
33
callPackage,
4-
nix-gitignore,
54

65
pyproject-nix,
76
pyproject-build-systems,
8-
uv2nix,
7+
kmir-pyk-pyproject,
8+
pyproject-overlays ? [ ],
99

1010
python,
1111
}:
1212
let
13+
inherit (kmir-pyk-pyproject) lockFileOverlay workspace;
14+
1315
pyproject-util = callPackage pyproject-nix.build.util { };
1416
pyproject-packages = callPackage pyproject-nix.build.packages { inherit python; };
1517

16-
src = callPackage ../kmir-source { };
17-
18-
# load a uv workspace from a workspace root
19-
workspace = uv2nix.lib.workspace.loadWorkspace { workspaceRoot = "${src}/kmir"; };
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-
2818
buildSystemsOverlay = import ./build-systems-overlay.nix;
2919

3020
# construct package set
3121
pythonSet = pyproject-packages.overrideScope (
32-
lib.composeManyExtensions [
33-
# make build tools available by default as these are not necessarily specified in python lock files
34-
pyproject-build-systems.overlays.default
35-
# include all packages from the python lock file
36-
lockFileOverlay
37-
# add build system overrides to certain python packages
38-
buildSystemsOverlay
39-
]
22+
lib.composeManyExtensions (
23+
[
24+
# make build tools available by default as these are not necessarily specified in python lock files
25+
pyproject-build-systems.overlays.default
26+
# include all packages from the python lock file
27+
lockFileOverlay
28+
# add build system overrides to certain python packages
29+
buildSystemsOverlay
30+
]
31+
++ pyproject-overlays
32+
)
4033
);
4134
in
4235
pyproject-util.mkApplication {

0 commit comments

Comments
 (0)