Skip to content

Commit caa17bb

Browse files
committed
cruft update
1 parent b6445e6 commit caa17bb

File tree

7 files changed

+149
-40
lines changed

7 files changed

+149
-40
lines changed

.cruft.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"template": "https://github.com/runtimeverification/python-project-template",
3-
"commit": "601d5e2a0e8a98c87dcb1ae694d22d76d0114e01",
3+
"commit": "7a095b4dd0a51916da0a728b8fdd9adf7e469a68",
44
"checkout": null,
55
"context": {
66
"cookiecutter": {
@@ -11,7 +11,8 @@
1111
"description": "",
1212
"author_name": "Runtime Verification, Inc.",
1313
"author_email": "[email protected]",
14-
"_template": "https://github.com/runtimeverification/python-project-template"
14+
"_template": "https://github.com/runtimeverification/python-project-template",
15+
"_commit": "7a095b4dd0a51916da0a728b8fdd9adf7e469a68"
1516
}
1617
},
1718
"directory": null

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
UV := uv --directory kmir
2-
UV_RUN := $(UV) run
2+
UV_RUN := $(UV) run --
33

44
PARALLEL := 4
55

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Also included is the `kmir` tool, a python script that acts as a front-end to th
99

1010
### KMIR Setup
1111

12-
Pre-requisites: `python >= 3.10`, `pip >= 20.0.2`, `poetry >= 1.3.2`, `gcc >= 11.4.0`, `cargo == nightly-2024-11-29`, `k >= v7.1.205`. To install K, follow the steps available in [K's Quick Start instructions](https://github.com/runtimeverification/k?tab=readme-ov-file#quick-start).
12+
Pre-requisites: `python >= 3.10`, [`uv`](https://docs.astral.sh/uv/), `pip >= 20.0.2`, `gcc >= 11.4.0`, `cargo == nightly-2024-11-29`, `k >= v7.1.205`. To install K, follow the steps available in [K's Quick Start instructions](https://github.com/runtimeverification/k?tab=readme-ov-file#quick-start).
1313

1414
```bash
1515
make build

flake.nix

Lines changed: 64 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,78 @@
11
{
22
description = "kmir - ";
33
inputs = {
4-
k-framework.url = "github:runtimeverification/k/v7.1.280";
5-
nixpkgs.follows = "k-framework/nixpkgs";
6-
flake-utils.follows = "k-framework/flake-utils";
4+
nixpkgs.url = "nixpkgs/nixos-25.05";
75
rv-nix-tools.follows = "k-framework/rv-nix-tools";
8-
# poetry2nix.follows = "k-framework/poetry2nix"; # FIXME: To stop crash with `nix flake update`
6+
7+
flake-utils.url = "github:numtide/flake-utils";
8+
k-framework.url = "github:runtimeverification/k/v7.1.280";
9+
10+
uv2nix.url = "github:pyproject-nix/uv2nix/680e2f8e637bc79b84268949d2f2b2f5e5f1d81c";
11+
# stale nixpkgs is missing the alias `lib.match` -> `builtins.match`
12+
# therefore point uv2nix to a patched nixpkgs, which introduces this alias
13+
# this is a temporary solution until nixpkgs us up-to-date again
14+
uv2nix.inputs.nixpkgs.url = "github:runtimeverification/nixpkgs/libmatch";
15+
# inputs.nixpkgs.follows = "nixpkgs";
16+
pyproject-build-systems.url = "github:pyproject-nix/build-system-pkgs/7dba6dbc73120e15b558754c26024f6c93015dd7";
17+
pyproject-build-systems = {
18+
inputs.nixpkgs.follows = "uv2nix/nixpkgs";
19+
inputs.uv2nix.follows = "uv2nix";
20+
inputs.pyproject-nix.follows = "uv2nix/pyproject-nix";
21+
};
22+
pyproject-nix.follows = "uv2nix/pyproject-nix";
923
};
10-
outputs = { self, nixpkgs, flake-utils, k-framework, ... }@inputs:
11-
let
12-
allOverlays = [
13-
k-framework.overlays.pyk
14-
(final: prev: let
15-
poetry2nix =
16-
inputs.poetry2nix.lib.mkPoetry2Nix { pkgs = prev; };
17-
in {
18-
kmir = poetry2nix.mkPoetryApplication {
19-
python = prev.python310;
20-
projectDir = ./kmir;
21-
overrides = poetry2nix.overrides.withDefaults
22-
(finalPython: prevPython: {
23-
kframework = prev.pyk-python310;
24-
});
25-
groups = [];
26-
# We remove `dev` from `checkGroups`, so that poetry2nix does not try to resolve dev dependencies.
27-
checkGroups = [];
28-
};
29-
})
30-
];
31-
in flake-utils.lib.eachSystem [
24+
outputs = { self, nixpkgs, rv-nix-tools, flake-utils, k-framework, pyproject-nix, pyproject-build-systems, uv2nix }:
25+
let
26+
pythonVer = "310";
27+
in flake-utils.lib.eachSystem [
3228
"x86_64-linux"
3329
"x86_64-darwin"
3430
"aarch64-linux"
3531
"aarch64-darwin"
3632
] (system:
37-
let
38-
pkgs = import nixpkgs {
39-
inherit system;
40-
overlays = allOverlays;
33+
let
34+
# due to the nixpkgs that we use in this flake being outdated, uv is also heavily outdated
35+
# we can instead use the binary release of uv provided by uv2nix for now
36+
uvOverlay = final: prev: {
37+
uv = uv2nix.packages.${final.system}.uv-bin;
38+
};
39+
mir-semanticsOverlay = final: prev: {
40+
mir-semantics = final.callPackage ./nix/mir-semantics {
41+
inherit pyproject-nix pyproject-build-systems uv2nix;
42+
python = final."python${pythonVer}";
4143
};
42-
in {
43-
packages = rec {
44-
inherit (pkgs) kmir;
45-
default = kmir;
44+
};
45+
pkgs = import nixpkgs {
46+
inherit system;
47+
overlays = [
48+
uvOverlay
49+
mir-semanticsOverlay
50+
];
51+
};
52+
python = pkgs."python${pythonVer}";
53+
in {
54+
devShells.default = pkgs.mkShell {
55+
name = "uv develop shell";
56+
buildInputs = [
57+
python
58+
pkgs.uv
59+
];
60+
env = {
61+
# prevent uv from managing Python downloads and force use of specific
62+
UV_PYTHON_DOWNLOADS = "never";
63+
UV_PYTHON = python.interpreter;
4664
};
47-
}) // {
48-
overlay = nixpkgs.lib.composeManyExtensions allOverlays;
65+
shellHook = ''
66+
unset PYTHONPATH
67+
'';
68+
};
69+
packages = rec {
70+
inherit (pkgs) mir-semantics;
71+
default = mir-semantics;
72+
};
73+
}) // {
74+
overlays.default = final: prev: {
75+
inherit (self.packages.${final.system}) mir-semantics;
4976
};
77+
};
5078
}

nix/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Notes
2+
#### git submodules
3+
If you use git submodules that are not required for building the project with `nix`, then you should add these directories to the `gitignoreSourcePure` list in `nix/mir-semantics/default.nix`, see the respective left-over `TODO` in the nix file. Otherwise, the nix build that is uploaded to the nix binary cache by CI might not match the version that is requested by `kup`, in case this project is offered as a package by `kup`. This is due to weird behaviour in regards to git submodules by `git` and `nix`, where a submodule directory might exist and be empty or instead not exist, which impacts the resulting nix hash, which is of impartance when offering/downloading cached nix derivations. See [runtimeverification/k/pull/4804](https://github.com/runtimeverification/k/pull/4804) for more information.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
final: prev:
2+
let
3+
inherit (final) resolveBuildSystem;
4+
inherit (builtins) mapAttrs;
5+
6+
# Build system dependencies specified in the shape expected by resolveBuildSystem
7+
# The empty lists below are lists of optional dependencies.
8+
#
9+
# A package `foo` with specification written as:
10+
# `setuptools-scm[toml]` in pyproject.toml would be written as
11+
# `foo.setuptools-scm = [ "toml" ]` in Nix
12+
buildSystemOverrides = {
13+
# add dependencies here, e.g.:
14+
# pyperclip.setuptools = [ ];
15+
};
16+
in
17+
mapAttrs (
18+
name: spec:
19+
prev.${name}.overrideAttrs (old: {
20+
nativeBuildInputs = old.nativeBuildInputs ++ resolveBuildSystem spec;
21+
})
22+
) buildSystemOverrides

nix/mir-semantics/default.nix

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
lib,
3+
callPackage,
4+
nix-gitignore,
5+
6+
pyproject-nix,
7+
pyproject-build-systems,
8+
uv2nix,
9+
10+
python
11+
}:
12+
let
13+
pyproject-util = callPackage pyproject-nix.build.util {};
14+
pyproject-packages = callPackage pyproject-nix.build.packages {
15+
inherit python;
16+
};
17+
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+
# do not include submodule directories that might be initilized empty or non-existent due to nix/git
25+
# otherwise cachix build might not match the version that is requested by `kup`
26+
# TODO: for new projects, add your submodule directories that are not required for nix builds here!
27+
# e.g., `"/docs/external-computation"` with `external-computation` being a git submodule directory
28+
# "/docs/external-computation"
29+
] ../..
30+
);
31+
};
32+
33+
# create overlay
34+
lockFileOverlay = workspace.mkPyprojectOverlay {
35+
# prefer "wheel" over "sdist" due to maintance overhead
36+
# there is no bundled set of overlays for "sdist" in uv2nix, in contrast to poetry2nix
37+
sourcePreference = "wheel";
38+
};
39+
40+
buildSystemsOverlay = import ./build-systems-overlay.nix;
41+
42+
# construct package set
43+
pythonSet = pyproject-packages.overrideScope (lib.composeManyExtensions [
44+
# make build tools available by default as these are not necessarily specified in python lock files
45+
pyproject-build-systems.overlays.default
46+
# include all packages from the python lock file
47+
lockFileOverlay
48+
# add build system overrides to certain python packages
49+
buildSystemsOverlay
50+
]);
51+
in pyproject-util.mkApplication {
52+
# default dependancy group enables no optional dependencies and no dependency-groups
53+
venv = pythonSet.mkVirtualEnv "mir-semantics-env" workspace.deps.default;
54+
package = pythonSet.mir-semantics;
55+
}

0 commit comments

Comments
 (0)