Skip to content

Commit 683a773

Browse files
authored
Add pyproject-nix overlay (#54)
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: `nix build github:runtimeverification/imp-semantics --override-input k-framework ~/path/to/local-k-checkout`. This will now also build kimp with the python and K code in `~/path/to/local-k-checkout`.
1 parent 12d16d4 commit 683a773

3 files changed

Lines changed: 47 additions & 20 deletions

File tree

flake.nix

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,22 @@
5252
};
5353
kimpOverlay = final: prev:
5454
let
55+
kimp-pyk-pyproject = final.callPackage ./nix/kimp-pyk-pyproject {
56+
inherit uv2nix;
57+
};
5558
kimp-pyk = final.callPackage ./nix/kimp-pyk {
56-
inherit pyproject-nix pyproject-build-systems uv2nix;
59+
inherit pyproject-nix pyproject-build-systems kimp-pyk-pyproject;
60+
pyproject-overlays = [
61+
(k-framework.overlays.pyk-pyproject system)
62+
];
5763
python = final."python${pythonVer}";
5864
};
5965
kimp = final.callPackage ./nix/kimp {
6066
inherit kimp-pyk;
6167
rev = self.rev or null;
6268
};
6369
in {
64-
inherit kimp;
70+
inherit kimp kimp-pyk kimp-pyk-pyproject;
6571
};
6672
pkgs = import nixpkgs {
6773
inherit system;
@@ -90,12 +96,19 @@
9096
'';
9197
};
9298
packages = rec {
93-
inherit (pkgs) kimp uv;
99+
inherit (pkgs) kimp uv kimp-pyk kimp-pyk-pyproject;
94100
default = kimp;
95101
};
96102
}) // {
97-
overlays.default = final: prev: {
98-
inherit (self.packages.${final.system}) kimp;
103+
overlays = {
104+
default = final: prev: {
105+
inherit (self.packages.${final.system}) kimp;
106+
};
107+
# this pyproject-nix overlay allows for overriding the python packages that are otherwise locked in `uv.lock`
108+
# by using this overlay in dependant nix flakes, you ensure that nix overrides also override the python package
109+
pyk-pyproject = system: final: prev: {
110+
inherit (self.packages.${system}.kimp-pyk-pyproject.lockFileOverlay final prev) kimp-pyk;
111+
};
99112
};
100113
};
101114
}

nix/kimp-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 ../kimp-source { };
9+
10+
# load a uv workspace from a workspace root
11+
workspace = uv2nix.lib.workspace.loadWorkspace {
12+
workspaceRoot = "${src}";
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/kimp-pyk/default.nix

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,30 @@
44

55
pyproject-nix,
66
pyproject-build-systems,
7-
uv2nix,
7+
kimp-pyk-pyproject,
8+
pyproject-overlays,
89

910
python
1011
}:
1112
let
13+
inherit (kimp-pyk-pyproject) lockFileOverlay workspace;
14+
1215
pyproject-util = callPackage pyproject-nix.build.util {};
1316
pyproject-packages = callPackage pyproject-nix.build.packages {
1417
inherit python;
1518
};
1619

17-
# load a uv workspace from a workspace root
18-
workspace = uv2nix.lib.workspace.loadWorkspace {
19-
workspaceRoot = callPackage ../kimp-source { };
20-
};
21-
22-
# create overlay
23-
lockFileOverlay = workspace.mkPyprojectOverlay {
24-
# prefer "wheel" over "sdist" due to maintance overhead
25-
# there is no bundled set of overlays for "sdist" in uv2nix, in contrast to poetry2nix
26-
sourcePreference = "wheel";
27-
};
28-
2920
buildSystemsOverlay = import ./build-systems-overlay.nix;
3021

3122
# construct package set
32-
pythonSet = pyproject-packages.overrideScope (lib.composeManyExtensions [
23+
pythonSet = pyproject-packages.overrideScope (lib.composeManyExtensions ([
3324
# make build tools available by default as these are not necessarily specified in python lock files
3425
pyproject-build-systems.overlays.default
3526
# include all packages from the python lock file
3627
lockFileOverlay
3728
# add build system overrides to certain python packages
3829
buildSystemsOverlay
39-
]);
30+
] ++ pyproject-overlays));
4031
in pyproject-util.mkApplication {
4132
# default dependancy group enables no optional dependencies and no dependency-groups
4233
venv = pythonSet.mkVirtualEnv "kimp-env" workspace.deps.default;

0 commit comments

Comments
 (0)