Skip to content

Commit 1f00cff

Browse files
committed
uv2nix
NixOS compatible Let's see if it works in GH actions
1 parent a952403 commit 1f00cff

4 files changed

Lines changed: 213 additions & 50 deletions

File tree

.envrc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
use flake . --impure
2-
uv sync
3-
source .venv/bin/activate
1+
use flake

Makefile

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
.PHONY: docs
22
test:
3-
nix develop --impure . -c uv run pre-commit run --all-files --show-diff-on-failure
4-
nix develop --impure . -c uv run ruff check .
5-
nix develop --impure . -c uv run --managed-python --python 3.10 coverage run -m pytest
6-
nix develop --impure . -c uv run --managed-python --python 3.11 coverage run -m pytest
7-
nix develop --impure . -c uv run --managed-python --python 3.12 coverage run -m pytest
8-
nix develop --impure . -c uv run --managed-python --python 3.13 coverage run -m pytest
9-
nix develop --impure . -c uv run coverage report
3+
nix develop --impure . -c pre-commit run --all-files --show-diff-on-failure
4+
nix develop --impure . -c ruff check .
5+
nix develop --impure .#python310 -c coverage run -m pytest
6+
nix develop --impure .#python311 -c coverage run -m pytest
7+
nix develop --impure .#python312 -c coverage run -m pytest
8+
nix develop --impure .#python313 -c coverage run -m pytest
9+
nix develop --impure . -c coverage report
1010
safety:
11-
nix develop --impure . -c uv run safety check --file=uv.lock --full-report
11+
nix develop --impure . -c safety check --file=uv.lock --full-report
1212
docs:
13-
nix develop --impure . -c uv run sphinx-build docs/source docs/_build
13+
nix develop --impure . -c sphinx-build docs/source docs/_build

flake.lock

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

flake.nix

Lines changed: 124 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,133 @@
11
{
2-
description = "A Nix flake-based development environment for working with stats_can";
2+
description = "Stats Can flake using uv2nix";
33

4-
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
7+
pyproject-nix = {
8+
url = "github:pyproject-nix/pyproject.nix";
9+
inputs.nixpkgs.follows = "nixpkgs";
10+
};
11+
12+
uv2nix = {
13+
url = "github:pyproject-nix/uv2nix";
14+
inputs.pyproject-nix.follows = "pyproject-nix";
15+
inputs.nixpkgs.follows = "nixpkgs";
16+
};
17+
18+
pyproject-build-systems = {
19+
url = "github:pyproject-nix/build-system-pkgs";
20+
inputs.pyproject-nix.follows = "pyproject-nix";
21+
inputs.uv2nix.follows = "uv2nix";
22+
inputs.nixpkgs.follows = "nixpkgs";
23+
};
24+
};
525

626
outputs =
7-
{ self, nixpkgs }:
27+
{
28+
self,
29+
nixpkgs,
30+
uv2nix,
31+
pyproject-nix,
32+
pyproject-build-systems,
33+
...
34+
}:
835
let
9-
supportedSystems = [
10-
"x86_64-linux"
11-
"aarch64-linux"
12-
"x86_64-darwin"
13-
"aarch64-darwin"
14-
];
15-
forEachSupportedSystem =
16-
f:
17-
nixpkgs.lib.genAttrs supportedSystems (
18-
system:
19-
f {
20-
pkgs = import nixpkgs {
21-
inherit system;
22-
config.allowUnfree = true;
23-
};
24-
}
25-
);
36+
inherit (nixpkgs) lib;
37+
38+
workspace = uv2nix.lib.workspace.loadWorkspace { workspaceRoot = ./.; };
39+
40+
overlay = workspace.mkPyprojectOverlay {
41+
sourcePreference = "wheel";
42+
};
43+
44+
pyprojectOverrides = _final: _prev: {
45+
# Implement build fixups here.
46+
};
47+
48+
pkgs = nixpkgs.legacyPackages.x86_64-linux;
49+
50+
pythonVersions = {
51+
python310 = pkgs.python310;
52+
python311 = pkgs.python311;
53+
python312 = pkgs.python312;
54+
python313 = pkgs.python313;
55+
default = pkgs.python313; # This will create a 'default' shell
56+
};
57+
58+
# --- CHANGED: A function to generate a dev shell for a given Python version ---
59+
# This function encapsulates all the logic that was previously hardcoded for a single Python version.
60+
mkPythonDevShell =
61+
python:
62+
let
63+
# 'pythonSet' is now defined inside this function, using the 'python' argument.
64+
pythonSet =
65+
(pkgs.callPackage pyproject-nix.build.packages {
66+
inherit python;
67+
}).overrideScope
68+
(
69+
lib.composeManyExtensions [
70+
pyproject-build-systems.overlays.default
71+
overlay
72+
pyprojectOverrides
73+
]
74+
);
75+
76+
# The rest of the shell-building logic is also moved inside.
77+
editableOverlay = workspace.mkEditablePyprojectOverlay {
78+
root = "$REPO_ROOT";
79+
};
80+
81+
editablePythonSet = pythonSet.overrideScope (
82+
lib.composeManyExtensions [
83+
editableOverlay
84+
(final: prev: {
85+
stats-can = prev.stats-can.overrideAttrs (old: {
86+
src = lib.fileset.toSource {
87+
root = old.src;
88+
fileset = lib.fileset.unions [
89+
(old.src + "/pyproject.toml")
90+
(old.src + "/README.md")
91+
(old.src + "/src/stats_can/__init__.py")
92+
];
93+
};
94+
nativeBuildInputs =
95+
old.nativeBuildInputs
96+
++ final.resolveBuildSystem {
97+
editables = [ ];
98+
};
99+
});
100+
})
101+
]
102+
);
103+
104+
virtualenv = editablePythonSet.mkVirtualEnv "stats-can-dev-env" workspace.deps.all;
105+
106+
in
107+
pkgs.mkShell {
108+
packages = [
109+
virtualenv
110+
pkgs.uv
111+
];
112+
113+
env = {
114+
UV_NO_SYNC = "1";
115+
# Use the 'python' argument to set the interpreter path.
116+
UV_PYTHON = python.interpreter;
117+
UV_PYTHON_DOWNLOADS = "never";
118+
};
119+
120+
shellHook = ''
121+
unset PYTHONPATH
122+
export REPO_ROOT=$(git rev-parse --show-toplevel)
123+
'';
124+
};
125+
26126
in
27127
{
28-
devShells = forEachSupportedSystem (
29-
{ pkgs }:
30-
{
31-
default = pkgs.mkShell {
32-
packages = with pkgs; [
33-
uv
34-
migrate-to-uv
35-
];
36-
};
37-
}
38-
);
128+
# --- CHANGED: Generate multiple dev shells using lib.mapAttrs ---
129+
# We map over the 'pythonVersions' set. For each entry, we call our 'mkPythonDevShell' function.
130+
# The key of the entry (e.g., "python312") becomes the name of the shell.
131+
devShells.x86_64-linux = lib.mapAttrs (_name: pythonPkg: mkPythonDevShell pythonPkg) pythonVersions;
39132
};
40133
}

0 commit comments

Comments
 (0)