Skip to content

Support Nix 2.34 - #26

Open
fasheng wants to merge 2 commits into
shlevy:masterfrom
fasheng:fix-nix-2.34
Open

fasheng wants to merge 2 commits into
shlevy:masterfrom
fasheng:fix-nix-2.34

Conversation

@fasheng

@fasheng fasheng commented Sep 3, 2026

Copy link
Copy Markdown

As usual, NixOS 26.05 brings Nix 2.34, and Nix 2.34 brings broken changes. This patch will fix compile errors for Nix 2.34.

BTW: This PR include #25 for it is required and still not be merged..

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

fasheng commented Sep 3, 2026

Copy link
Copy Markdown
Author

Thanks @avidal. Here is a sample flake.nix like #25 did.

{
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/c5c4a43b"; # nixos-26.05 20260901

  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_34;
          nixComponents = pkgs.nixVersions.nixComponents_2_34;

          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);
                 }
              '')
              (pkgs.writeText "nix-2.34.patch" ''
                --- a/extra-builtins.cc
                +++ b/extra-builtins.cc
                @@ -12,8 +12,8 @@
                 using namespace nix;
                 
                 struct ExtraBuiltinsSettings : Config {
                -    Setting<Path> extraBuiltinsFile{this,
                -        settings.nixConfDir + "/extra-builtins.nix",
                +    Setting<std::filesystem::path> extraBuiltinsFile{this,
                +        nixConfDir() + "/extra-builtins.nix",
                             "extra-builtins-file",
                             "The path to a nix expression defining extra expression-language level builtins."};
                 };
                @@ -42,14 +42,14 @@ static void extraBuiltins(EvalState & state, const PosIdx pos,
                             attrs.alloc(sExec).mkPrimOp(new PrimOp {
                                 .name = "exec",
                                 .arity = 1,
                -                .fun = prim_exec,
                +                .impl = prim_exec,
                             });
                 
                             auto sImportNative = state.symbols.create("importNative");
                             attrs.alloc(sImportNative).mkPrimOp(new PrimOp {
                                 .name = "importNative",
                                 .arity = 2,
                -                .fun = prim_importNative,
                +                .impl = prim_importNative,
                             });
                 
                             arg = state.allocValue();
                @@ -65,7 +65,7 @@ static void extraBuiltins(EvalState & state, const PosIdx pos,
                 static RegisterPrimOp rp1({
                     .name = "__extraBuiltins",
                     .arity = 0,
                -    .fun = extraBuiltins,
                +    .impl = extraBuiltins,
                 });
                 
                 static void cflags(EvalState & state, const PosIdx _pos,
                @@ -81,5 +81,5 @@ static void cflags(EvalState & state, const PosIdx _pos,
                 static RegisterPrimOp rp2({
                     .name = "__nix-cflags",
                     .arity = 0,
                -    .fun = cflags,
                +    .impl = cflags,
                 });
                '')
            ];
          });

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

Test commands:

nix develop .#fixed
$ nix eval --expr 'builtins.extraBuiltins'

NOTE: If the host enabled nix-plugins, the test commands will print the builtins.extraBuiltins that defined in host's /etc/nix/nix.conf

@fasheng

fasheng commented Sep 3, 2026

Copy link
Copy Markdown
Author

Consider NixOS/Nix always broken nix-plugins, here is my Tips:

  1. Under any cases, If the nix version of the system to be deployed changes, the first thing to do is to block the nix-plugins related configuration of the current system and execute the nixos-rebuild switch:

    # nix.settings.plugin-files = "${pkgs.nix-plugins}/lib/nix/plugins";
    # nix.settings.extra-builtins-file = [ ./extra-builtins.nix ];

    Otherwise, directly deploying the system will report an error:

    > error: could not dynamically open plugin file "/nix/store/184qp79qgycbhvx3nknafqzng7xd85jw-nix-plugins-16.0.1/lib/nix/plugins/libnix-extra-builtins.so": /nix/store/184qp79qgycbhvx3nknafqzng7xd85jw-nix-plugins-16.0.1/lib/nix/plugins/libnix-extra-builtins.so: undefined symbol: _ZN3nix6Config11getSettingsERSt3mapINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEENS_14AbstractConfig11SettingInfoESt4lessIS7_ESaISt4pairIKS7_S9_EEEb
           For full logs, run:
             nix log /nix/store/c64h8w3wabl0prfmbnjvinn02s8fq7wi-nix.conf.drv
    
  2. If the nix-plugins still report an error, a workaround is to change the nixComponents of nix-plugins. For example the following config works with NixOS 25.11:

    let
      nix-plugins-fixed = pkgs.nix-plugins.override {
        nixComponents = pkgs.nixVersions.nixComponents_2_31;
      };
    in
    {
      nix.settings.plugin-files = "${nix-plugins-fixed}/lib/nix/plugins";
      nix.settings.extra-builtins-file = [ ./extra-builtins.nix ];
    }

    https://discourse.nixos.org/t/unable-to-get-nix-plugins-to-work/67426/2

  3. If the nix-plugins still report an error, another workaround is keep the nix version not changed. For example the following config works with NixOS 26.05(c5c4a43b):

    nix.package = pkgs.nixVersions.nix_2_31;

    NOTE: If you want to switch to another nix version, just follow Tips 1.

  4. Generally, once your configurations about nix-plugins changed, you should run nixos-rebuild switch twice to apply it

  5. nix-plugins build commands:

    nix develop
    $ mkdir build
    $ cd build
    $ cmake ..
    $ cmake --build .

@fasheng fasheng mentioned this pull request Sep 3, 2026
As usual, NixOS 26.05 brings Nix 2.34, and Nix 2.34 brings broken changes. This patch will fix compile errors for Nix 2.34.

BTW: This PR include shlevy#25 for it is required and still not be merged..
@shlevy

shlevy commented Sep 6, 2026

Copy link
Copy Markdown
Owner

Will review this week, thanks

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.

3 participants