Skip to content

nix 2.33+ patch#25

Open
avidal wants to merge 1 commit intoshlevy:masterfrom
avidal:patch-1
Open

nix 2.33+ patch#25
avidal wants to merge 1 commit intoshlevy:masterfrom
avidal:patch-1

Conversation

@avidal
Copy link

@avidal avidal commented Jan 28, 2026

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.

In NixOS/nix#14584 mkString was changed to require an `EvalMemory`, part of a larger effort to centralize memory allocation.
@avidal
Copy link
Author

avidal commented Jan 28, 2026

A minimal flake to reproduce (which inlines the patch) is attached.

You can test it with nix develop .#broken which will fail to build, and nix develop .#fixed which includes the patch.

{
  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;
        }
      );
    };
}

@avidal
Copy link
Author

avidal commented Jan 28, 2026

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:

{
    inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

    outputs = { nixpkgs, ... }:
      let
        pkgs = nixpkgs.legacyPackages.aarch64-darwin; # or your system
      in
      {
        devShells.aarch64-darwin.default = pkgs.mkShell {
          packages = [ pkgs.nixVersions.nix_2_32 ];
          NIX_CONFIG = ''
            plugin-files = ${pkgs.nix-plugins.override {
              nixComponents = pkgs.nixVersions.nixComponents_2_32;
            }}/lib/nix/plugins
          '';
        };
      };
  }

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 importEncrypted builtin, for example, you'll need to do your nixos-rebuild calls from within your devshell.

@samos667
Copy link

samos667 commented Feb 1, 2026

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
          '';
        }
      ];
    };
  };
}
# nix repl --expr $"builtins.getFlake \"($env.PWD)\""
Nix (Determinate Nix 3.15.2) 2.33.1
Type :? for help.
Loading installable ''...
Added 18 variables.
"@", _type, apps, checks, devShells, formatter, globals, inputs, legacyPackages, nixosConfigurations, nixosModules, nodes, outPath, outputs, overlays, pa
ckages, pkgs, sourceInfo
nix-repl> builtins.extraBuiltins.rageImportEncrypted
«lambda rageImportEncrypted @ /nix/store/klrpmwh5qnqzi3r79dcz3jm91kiq62s9-default/extra-builtins.nix:30:25»

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants