Skip to content

Commit 64e59b7

Browse files
hussainsultanjackiekazil
authored andcommitted
fix(flake): add darwin system and required overrides
1 parent 7a7cad0 commit 64e59b7

File tree

4 files changed

+1233
-1128
lines changed

4 files changed

+1233
-1128
lines changed

flake.lock

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 49 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
12
{
23
description = "Mesa flake using uv2nix";
34

45
inputs = {
56
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
7+
flake-utils.url = "github:numtide/flake-utils";
68

79
pyproject-nix = {
810
url = "github:pyproject-nix/pyproject.nix";
@@ -24,50 +26,61 @@
2426
};
2527

2628
outputs =
27-
{
28-
self,
29-
nixpkgs,
30-
uv2nix,
31-
pyproject-nix,
32-
pyproject-build-systems,
33-
...
29+
{ self
30+
, nixpkgs
31+
, flake-utils
32+
, uv2nix
33+
, pyproject-nix
34+
, pyproject-build-systems
35+
, ...
3436
}:
37+
38+
flake-utils.lib.eachSystem ["x86_64-linux" "aarch64-darwin"] (system:
3539
let
3640
inherit (nixpkgs) lib;
3741

42+
# Use system-specific pkgs
43+
pkgs = nixpkgs.legacyPackages.${system};
44+
3845
# Load a uv workspace from a workspace root.
3946
# Uv2nix treats all uv projects as workspace projects.
4047
workspace = uv2nix.lib.workspace.loadWorkspace { workspaceRoot = ./.; };
4148

4249
# Create package overlay from workspace.
4350
overlay = workspace.mkPyprojectOverlay {
44-
# Prefer prebuilt binary wheels as a package source.
45-
# Sdists are less likely to "just work" because of the metadata missing from uv.lock.
46-
# Binary wheels are more likely to, but may still require overrides for library dependencies.
4751
sourcePreference = "wheel"; # or sourcePreference = "sdist";
48-
# Optionally customise PEP 508 environment
49-
# environ = {
50-
# platform_release = "5.10.65";
51-
# };
5252
};
5353

54-
# Extend generated overlay with build fixups
55-
#
56-
# Uv2nix can only work with what it has, and uv.lock is missing essential metadata to perform some builds.
57-
# This is an additional overlay implementing build fixups.
58-
# See:
59-
# - https://pyproject-nix.github.io/uv2nix/FAQ.html
60-
pyprojectOverrides = _final: _prev: {
61-
# Implement build fixups here.
62-
# Note that uv2nix is _not_ using Nixpkgs buildPythonPackage.
63-
# It's using https://pyproject-nix.github.io/pyproject.nix/build.html
64-
};
54+
python = pkgs.python312;
6555

66-
# This example is only using x86_64-linux
67-
pkgs = nixpkgs.legacyPackages.x86_64-linux;
56+
pyprojectOverrides = final: prev: {
57+
# Add the scipy override (need to do uv add pythran)
58+
scipy = prev.scipy.overrideAttrs (old: {
59+
nativeBuildInputs = (old.nativeBuildInputs or []) ++ [
60+
final.meson-python
61+
final.ninja
62+
final.cython
63+
final.numpy
64+
final.pybind11
65+
final.packaging
66+
final.pyproject-metadata
67+
final.pythran
68+
final.gast
69+
final.beniget
70+
final.ply
71+
];
6872

69-
# Use Python 3.12 from nixpkgs
70-
python = pkgs.python312;
73+
buildInputs = (old.buildInputs or []) ++ [
74+
pkgs.gfortran
75+
pkgs.cmake
76+
pkgs.xsimd
77+
pkgs.pkg-config
78+
pkgs.openblas
79+
pkgs.meson
80+
pkgs.lapack
81+
];
82+
});
83+
};
7184

7285
# Construct package set
7386
pythonSet =
@@ -88,19 +101,19 @@
88101
# Package a virtual environment as our main application.
89102
#
90103
# Enable no optional dependencies for production build.
91-
packages.x86_64-linux.default = pythonSet.mkVirtualEnv "mesa-env" workspace.deps.default;
104+
packages.default = pythonSet.mkVirtualEnv "mesa-env" workspace.deps.default;
92105

93-
apps.x86_64-linux = {
106+
apps = {
94107
default = {
95108
type = "app";
96-
program = "${self.packages.x86_64-linux.default}/bin/ipython";
109+
program = "${self.packages.${system}.default}/bin/ipython";
97110
};
98111
};
99112

100113
# This example provides two different modes of development:
101114
# - Impurely using uv to manage virtual environments
102115
# - Pure development using uv2nix to manage virtual environments
103-
devShells.x86_64-linux = {
116+
devShells = {
104117
# It is of course perfectly OK to keep using an impure virtualenv workflow and only use uv2nix to build packages.
105118
# This devShell simply adds Python and undoes the dependency leakage done by Nixpkgs Python infrastructure.
106119
impure = pkgs.mkShell {
@@ -183,7 +196,6 @@
183196
# Enable all optional dependencies for development.
184197
virtualenv = editablePythonSet.mkVirtualEnv "mesa-dev-env" workspace.deps.all;
185198

186-
187199
in
188200
pkgs.mkShell {
189201
packages = [
@@ -217,8 +229,8 @@
217229
fi
218230
'';
219231
};
220-
# set uv2nix devShell as default nix develop .#uv2nix
221-
default = self.devShells.x86_64-linux.uv2nix;
232+
# set uv2nix devShell as default
233+
default = self.devShells.${system}.uv2nix;
222234
};
223-
};
235+
});
224236
}

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ dependencies = [
3939
"pandas",
4040
"tqdm",
4141
"scipy",
42-
"ipython>=9.2.0",
42+
"pythran>=0.17.0 ; sys_platform == 'darwin'", # required for darwin scipy overrides in nix
43+
4344
]
4445
dynamic = ["version"]
4546

@@ -64,6 +65,7 @@ dev = [
6465
"pytest-cov",
6566
"sphinx",
6667
"pytest-mock",
68+
"ipython>=9.2.0",
6769
]
6870
examples = [
6971
"mesa[rec]",

0 commit comments

Comments
 (0)