Open
Conversation
In NixOS/nix#14584 mkString was changed to require an `EvalMemory`, part of a larger effort to centralize memory allocation.
Author
|
A minimal flake to reproduce (which inlines the patch) is attached. You can test it with {
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
outputs = { nixpkgs, ... }:
let
forAllSystems = f: nixpkgs.lib.genAttrs
[ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]
(system: f nixpkgs.legacyPackages.${system});
in
{
devShells = forAllSystems (pkgs:
let
nix = pkgs.nixVersions.nix_2_33;
nixComponents = pkgs.nixVersions.nixComponents_2_33;
nix-plugins-broken = pkgs.nix-plugins.override { inherit nixComponents; };
nix-plugins-fixed = nix-plugins-broken.overrideAttrs (old: {
patches = (old.patches or [ ]) ++ [
(pkgs.writeText "nix-2.33.patch" ''
--- a/extra-builtins.cc
+++ b/extra-builtins.cc
@@ -72,9 +72,9 @@ static void cflags(EvalState & state, const PosIdx _pos,
Value ** _args, Value & v)
{
auto attrs = state.buildBindings(3);
- attrs.alloc("NIX_INCLUDE_DIRS").mkString(NIX_INCLUDE_DIRS);
- attrs.alloc("NIX_CFLAGS_OTHER").mkString(NIX_CFLAGS_OTHER);
- attrs.alloc("BOOST_INCLUDE_DIR").mkString(BOOST_INCLUDE_DIR);
+ attrs.alloc("NIX_INCLUDE_DIRS").mkString(NIX_INCLUDE_DIRS, state.mem);
+ attrs.alloc("NIX_CFLAGS_OTHER").mkString(NIX_CFLAGS_OTHER, state.mem);
+ attrs.alloc("BOOST_INCLUDE_DIR").mkString(BOOST_INCLUDE_DIR, state.mem);
v.mkAttrs(attrs);
}
'')
];
});
extra-builtins = pkgs.writeText "extra-builtins.nix" ''
{ ... }: { hello = "nix-plugins works!"; }
'';
mkShell = nix-plugins: pkgs.mkShell {
packages = [ nix ];
NIX_CONFIG = ''
plugin-files = ${nix-plugins}/lib/nix/plugins
extra-builtins-file = ${extra-builtins}
'';
};
in
{
broken = mkShell nix-plugins-broken;
fixed = mkShell nix-plugins-fixed;
default = mkShell nix-plugins-fixed;
}
);
};
} |
Author
|
For folks that don't want to manually patch but instead pin their devshell to nix 2.32 (latest version that nix-plugins will build in), you can do something like this: And as long as you do your work that needs the extra-builtins from your devshell, it'll work. The outer nix may be 2.33, but in the devshell it'll be 2.32. If you're using this for things like oddlama/nix-config where you have an |
|
Thanks! That work perfectly with the latest determinate(d) nix {inputs, ...}: {
imports = [
inputs.devshell.flakeModule
];
perSystem = {
pkgs,
system,
...
}: let
# inputs.determinate-nix.url = "https://flakehub.com/f/DeterminateSystems/nix-src/3.15.2.tar.gz";
determinate-nix = inputs.determinate-nix.packages."${system}".default;
nix-plugins-fixed = pkgs.nix-plugins.overrideAttrs (old: {
buildInputs = [determinate-nix pkgs.boost];
patches =
(old.patches or [])
++ [
(pkgs.writeText "nix-2.33.patch" ''
--- a/extra-builtins.cc
+++ b/extra-builtins.cc
@@ -72,9 +72,9 @@ static void cflags(EvalState & state, const PosIdx _pos,
Value ** _args, Value & v)
{
auto attrs = state.buildBindings(3);
- attrs.alloc("NIX_INCLUDE_DIRS").mkString(NIX_INCLUDE_DIRS);
- attrs.alloc("NIX_CFLAGS_OTHER").mkString(NIX_CFLAGS_OTHER);
- attrs.alloc("BOOST_INCLUDE_DIR").mkString(BOOST_INCLUDE_DIR);
+ attrs.alloc("NIX_INCLUDE_DIRS").mkString(NIX_INCLUDE_DIRS, state.mem);
+ attrs.alloc("NIX_CFLAGS_OTHER").mkString(NIX_CFLAGS_OTHER, state.mem);
+ attrs.alloc("BOOST_INCLUDE_DIR").mkString(BOOST_INCLUDE_DIR, state.mem);
v.mkAttrs(attrs);
}
'')
];
});
in {
devshells.default = {
packages = with pkgs; [
determinate-nix
];
env = [
{
name = "NIX_CONFIG";
value = ''
plugin-files = ${nix-plugins-fixed}/lib/nix/plugins
extra-builtins-file = ${./.}/extra-builtins.nix
'';
}
];
};
};
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In NixOS/nix#14584 mkString was changed to require an
EvalMemory, part of a larger effort to centralize memory allocation.Disclaimer: Claude wrote this patch. While I am a software developer I'm not a C++ developer, nor do I have a lot of experience with Nix (yet). I just wanted to contribute back the fix.