Skip to content

Commit 3e34201

Browse files
fusion44claude
andcommitted
refactor(flake): expose lib.mkBlitzApi for consumer-pkgs builds
Extract the Python virtualenv build into `mkBlitzApi { pkgs, python ? null }` and expose it as `lib.mkBlitzApi`. Rewrite `overlays.default` to call the builder against the consumer's `prev` instead of pulling from `self.packages.${system}` (which captured this flake's pinned nixpkgs at flake-eval time and shut consumer overlays out of the build hook). Motivation: NixBlitz pulls blitz-api's flake via `builtins.getFlake` to keep the plugin self-contained. Without a pkgs-agnostic builder, the operator's nixpkgs overlays (Pi 5 jemalloc page-size patch and similar platform fixes) couldn't reach blitz-api's build, so the package would either fail to compile on Pi 5 or silently link against this flake's pinned nixpkgs and pull a second snapshot of glibc / openssl / etc. into the operator's closure. The `packages.${system}.${name}` attribute is preserved as a convenience pre-built using this flake's pinned nixpkgs; consumers that want consumer-pkgs builds should use `overlays.default` or `lib.mkBlitzApi` directly. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 1081b71 commit 3e34201

1 file changed

Lines changed: 52 additions & 26 deletions

File tree

flake.nix

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,54 +35,80 @@
3535
}: let
3636
name = "blitz-api";
3737

38-
# Load the uv workspace once; reused across systems.
38+
# Load the uv workspace once. Pure Nix value — independent of
39+
# the consumer's pkgs, only depends on this repo's source tree.
3940
workspace = uv2nix.lib.workspace.loadWorkspace {workspaceRoot = ./.;};
4041

41-
# Pure Nix overlay derived from pyproject.toml + uv.lock. Prefer
42-
# prebuilt wheels — a handful of deps (grpcio, psutil, pyzmq) are
43-
# painful to compile from source and wheels work fine on linux/darwin.
44-
overlay = workspace.mkPyprojectOverlay {
42+
# Pyproject-nix overlay derived from pyproject.toml + uv.lock.
43+
# Prefer prebuilt wheels — a handful of deps (grpcio, psutil,
44+
# pyzmq) are painful to compile from source and wheels work
45+
# fine on linux/darwin. Also pkgs-independent.
46+
pyprojectOverlay = workspace.mkPyprojectOverlay {
4547
sourcePreference = "wheel";
4648
};
4749

50+
# Build the blitz-api Python virtualenv against the CALLER's
51+
# pkgs. Exposed as `lib.mkBlitzApi` so consumers (NixBlitz
52+
# plugin, downstream embedders) can build the package using
53+
# their own nixpkgs — important when the consumer needs a
54+
# platform-specific patch that this flake's pinned
55+
# nixos-unstable doesn't carry yet.
56+
#
57+
# Without this, the package would be built once at THIS flake's
58+
# eval time using THIS flake's pinned nixpkgs, and consumer
59+
# overlays couldn't reach the build hook.
60+
mkBlitzApi = {
61+
pkgs,
62+
python ? null,
63+
}: let
64+
py =
65+
if python != null
66+
then python
67+
else pkgs.python312;
68+
pythonSet = (pkgs.callPackage pyproject-nix.build.packages {python = py;})
69+
.overrideScope (
70+
pkgs.lib.composeManyExtensions [
71+
pyproject-build-systems.overlays.default
72+
pyprojectOverlay
73+
]
74+
);
75+
in
76+
pythonSet.mkVirtualEnv "${name}-env" workspace.deps.default;
77+
78+
# Library output — what callers reach for to build the package
79+
# under their own pkgs.
80+
libOutput = {
81+
lib = {inherit mkBlitzApi;};
82+
};
83+
4884
systems = flake-utils.lib.eachDefaultSystem (system: let
4985
pkgs = nixpkgs.legacyPackages.${system};
50-
python = pkgs.python312;
51-
52-
pythonSet =
53-
(pkgs.callPackage pyproject-nix.build.packages {
54-
inherit python;
55-
})
56-
.overrideScope (
57-
nixpkgs.lib.composeManyExtensions [
58-
pyproject-build-systems.overlays.default
59-
overlay
60-
]
61-
);
6286
in {
6387
packages = {
6488
default = self.packages.${system}.${name};
65-
${name} = pythonSet.mkVirtualEnv "${name}-env" workspace.deps.default;
89+
# Convenience: a pre-built package using THIS flake's pinned
90+
# nixpkgs. Most consumers should use `overlays.default` or
91+
# `lib.mkBlitzApi` instead so the package builds against
92+
# their pkgs.
93+
${name} = mkBlitzApi {inherit pkgs;};
6694
};
6795
});
6896

6997
overlays.overlays = {
98+
# Re-runs `mkBlitzApi` against the consumer's `prev` pkgs so the
99+
# consumer's overlays (Pi 5 page-size patch, custom uv pin, etc.)
100+
# are in scope when the package is built.
70101
default = final: prev: {
71-
${name} = self.packages.${prev.stdenv.hostPlatform.system}.${name};
102+
${name} = mkBlitzApi {pkgs = prev;};
72103
};
73104
};
74105

75106
module = {
76-
nixosModules.default = {
77-
pkgs,
78-
lib,
79-
config,
80-
...
81-
}: {
107+
nixosModules.default = {...}: {
82108
imports = [./modules/blitz_api.nix];
83109
nixpkgs.overlays = [self.overlays.default];
84110
};
85111
};
86112
in
87-
systems // overlays // module;
113+
systems // overlays // module // libOutput;
88114
}

0 commit comments

Comments
 (0)