Skip to content

Outdated functions in C APIΒ #7

Open
@o-santi

Description

@o-santi

Describe the bug
The C API used in this library seems to be outdated. Given that the corresponding nix-c-bindings branch has been merged to master, it might be valuable to make sure it works with the newest version.

To Reproduce
Use python-nix with an up to date version of nix with C bindings, making sure to override the nix input to the newest version. The following flake uses the most up to date (2.22) version, but I've tested other versions that also don't work (tested with 2.21 and 2.20).

# flake.nix
{
  inputs = {
    python-nix = {
      url = "github:tweag/python-nix";
      inputs.nix.follows = "nix";
    };
    nix.url = "github:NixOs/nix";
    nixpkgs.follows = "nix/nixpkgs";
  };
  outputs = inputs @ { self, python-nix, nixpkgs, ...} :
    let
      system = "x86_64-linux";
      nix = inputs.nix.packages.${system}.default;
      pkgs = import nixpkgs {
        inherit system;
      };
    in
    {
      devShells.${system}.default = pkgs.mkShell {
        buildInputs = [
          (pkgs.python3.withPackages (_: [ nix python-nix.packages.${system}.default ]))
        ];
      };
    };
}

Then, in a shell.

$ nix develop
$ python3
Python 3.11.6 (main, Oct  2 2023, 13:45:54) [GCC 12.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import nix
>>> nix.eval('1 + 1')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/nix/store/3rb1nsykazqlgbagx6f227sdx17w805g-python3-3.11.6-env/lib/python3.11/site-packages/nix/__init__.py", line 20, in eval
    _store = Store()
             ^^^^^^^
  File "/nix/store/3rb1nsykazqlgbagx6f227sdx17w805g-python3-3.11.6-env/lib/python3.11/site-packages/nix/store.py", line 40, in __init__
    self._store = ffi.gc(lib.nix_store_open(url_c, params_c), lib.nix_store_unref)
                                                              ^^^^^^^^^^^^^^^^^^^
  File "/nix/store/3rb1nsykazqlgbagx6f227sdx17w805g-python3-3.11.6-env/lib/python3.11/site-packages/nix/wrap.py", line 55, in __getattr__
    r: Any = wrap_ffi(getattr(self._thing, attr))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: cffi library 'nix._nix_api_store' has no function, constant or global variable named 'nix_store_unref'. Did you mean: 'nix_store_free'?
>>> 

Expected behavior
Output the number two.

Environment

  • NixOS 24.05.20240329.d8fe5e6 (Uakari)
  • Version of the code: master.

Additional context
This seems to be a name change of the function, from nix_store_unref to nix_store_free, though I'm not sure what else changed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions