Skip to content

Commit e3b8b87

Browse files
jmmaloney4claude
andcommitted
fix(rust): resolve architectural inconsistency in nixpkgs handling
## Problem The rust kernel had an architectural inconsistency where it used two different approaches to access nixpkgs packages: 1. **Module-level**: `requiredRuntimePackages = [config.nixpkgs.cargo ...]` 2. **Function-level**: `pkgs = import config.nixpkgs.path { ... }` This caused evaluation failures when `config.nixpkgs.cargo` was undefined, since users were only providing nixpkgs configuration (path + overlays) rather than an instantiated package set. ## Root Cause Analysis **Timeline of the inconsistency:** - **Feb 9, 2023** (commit 9fc7d31): GuangTao Zhang introduced centralized `config.nixpkgs` system. Rust kernel correctly used `config.nixpkgs.*` - **Mar 16, 2023** (commit 0fea293): Dan Baker's "refactor/turn kernels into modules" **accidentally combined two patterns**: - Preserved module-level `config.nixpkgs.cargo` (correct for that system) - Added function-level custom nixpkgs import (newer, more flexible approach) - **July 19, 2025**: Recent improvements (commits 55655e3, 4d5f37c, e19f799) enhanced flexibility but **inconsistency remained unfixed** **Why it persisted:** The inconsistency was masked because module-level `requiredRuntimePackages` usually overrode function-level defaults. Only surfaced when users customized the kernel configuration. ## Solution Updated `requiredRuntimePackages` to use the same `pkgs` instance that's created with custom overlays, making the rust kernel architecturally consistent: ```nix # Before: Mixed approaches requiredRuntimePackages = [config.nixpkgs.cargo ...]; # Uses config.nixpkgs pkgs = import config.nixpkgs.path { overlays = ...; }; # Creates custom pkgs # After: Consistent approach pkgs = import config.nixpkgs.path { overlays = ...; }; # Create pkgs first requiredRuntimePackages = [pkgs.cargo ...]; # Use same pkgs ``` This aligns the rust kernel with its own architectural pattern and eliminates the dependency on `config.nixpkgs` being a package set. ## Testing Verified the fix resolves evaluation errors in downstream projects that configure rust kernels with custom nixpkgs paths and overlays. Fixes tweag#564 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent e19f799 commit e3b8b87

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

modules/kernels/rust/default.nix

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,19 @@
2828
name,
2929
...
3030
}: let
31+
# Create the custom pkgs with overlays applied first
32+
pkgs = let
33+
allOverlays = config.overlays ++ config.nixpkgs.extraOverlays;
34+
in
35+
import config.nixpkgs.path {
36+
inherit system;
37+
overlays = allOverlays;
38+
};
39+
3140
requiredRuntimePackages = [
32-
config.nixpkgs.cargo
33-
config.nixpkgs.gcc
34-
config.nixpkgs.binutils-unwrapped
41+
pkgs.cargo
42+
pkgs.gcc
43+
pkgs.binutils-unwrapped
3544
];
3645
args = {inherit self system lib config name kernelName requiredRuntimePackages;};
3746
kernelModule = import ./../../kernel.nix args;
@@ -145,7 +154,7 @@
145154
kernelModule.kernelArgs
146155
// {
147156
inherit (config) evcxr;
148-
# Import nixpkgs with all overlays applied
157+
# Import nixpkgs with all overlays applied (same as used for requiredRuntimePackages)
149158
pkgs = let
150159
allOverlays = config.overlays ++ config.nixpkgs.extraOverlays;
151160
in

0 commit comments

Comments
 (0)