feat: update nix input to latest master

The nix c bindings have now merged into master, with some small changes since these bindings were created.
This commit updates the input, and adjusts it to the new API.

(cherry picked from commit aa02380bfcc6221615f65152de60cf4cca3bbbbe)
This commit is contained in:
Erin van der Veen 2024-04-23 13:23:42 +02:00 committed by Robert Hensing
parent af86728386
commit 9d26e36b85
4 changed files with 109 additions and 16 deletions

103
flake.lock generated
View file

@ -92,10 +92,49 @@
"type": "github"
}
},
"flake-parts_2": {
"inputs": {
"nixpkgs-lib": [
"nix",
"nixpkgs"
]
},
"locked": {
"lastModified": 1712014858,
"narHash": "sha256-sB4SWl2lX95bExY2gMFG5HIzvva5AVMJd4Igm+GpZNw=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "9126214d0a59633752a136528f5f3b9aa8565b7d",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"inputs": {
"systems": "systems_2"
},
"locked": {
"lastModified": 1701680307,
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
@ -166,23 +205,24 @@
"nix": {
"inputs": {
"flake-compat": "flake-compat",
"flake-parts": "flake-parts_2",
"libgit2": "libgit2",
"nixpkgs": [
"nixpkgs"
],
"nixpkgs-regression": "nixpkgs-regression"
"nixpkgs-regression": "nixpkgs-regression",
"pre-commit-hooks": "pre-commit-hooks"
},
"locked": {
"lastModified": 1711717219,
"narHash": "sha256-8nzsGORuUIkM91yKYz9f8/+eRMrLRHrqs+ExwLT01+8=",
"owner": "tweag",
"lastModified": 1713862243,
"narHash": "sha256-mfJSQyO7je+/WSBmnl/LTGvqrzv3k1F0kEd7Wg+VXw4=",
"owner": "nixos",
"repo": "nix",
"rev": "926fbadcc30a4614b5f5a3d18a6f4096914f97da",
"rev": "1cfc9da472f8dcfa7f521e544531d5e4daf2076c",
"type": "github"
},
"original": {
"owner": "tweag",
"ref": "nix-c-bindings",
"owner": "nixos",
"repo": "nix",
"type": "github"
}
@ -282,10 +322,42 @@
"type": "github"
}
},
"pre-commit-hooks": {
"inputs": {
"flake-compat": [
"nix"
],
"flake-utils": "flake-utils",
"gitignore": [
"nix"
],
"nixpkgs": [
"nix",
"nixpkgs"
],
"nixpkgs-stable": [
"nix",
"nixpkgs"
]
},
"locked": {
"lastModified": 1713775815,
"narHash": "sha256-Wu9cdYTnGQQwtT20QQMg7jzkANKQjwBD9iccfGKkfls=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "2ac4dcbf55ed43f3be0bae15e181f08a57af24a4",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"pre-commit-hooks-nix": {
"inputs": {
"flake-compat": "flake-compat_2",
"flake-utils": "flake-utils",
"flake-utils": "flake-utils_2",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
@ -409,6 +481,21 @@
"type": "github"
}
},
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"treefmt": {
"inputs": {
"nixpkgs": [

View file

@ -4,7 +4,7 @@
inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
nix.url = "github:tweag/nix/nix-c-bindings";
nix.url = "github:nixos/nix";
nix.inputs.nixpkgs.follows = "nixpkgs";
nix-cargo-integration.url = "github:yusdacra/nix-cargo-integration";
nix-cargo-integration.inputs.nixpkgs.follows = "nixpkgs";

View file

@ -5,6 +5,7 @@ use lazy_static::lazy_static;
use nix_c_raw as raw;
use nix_store::store::Store;
use nix_util::context::Context;
use nix_util::string_return::callback_get_vec_u8;
use std::ffi::CString;
use std::ptr::null_mut;
use std::ptr::NonNull;
@ -108,13 +109,18 @@ impl EvalState {
}
/// Not exposed, because the caller must always explicitly handle the context or not accept one at all.
fn get_string(&self, value: &Value) -> Result<String> {
let c_str_raw = unsafe { raw::nix_get_string(self.context.ptr(), value.raw_ptr()) };
let mut raw_buffer: Vec<u8> = Vec::new();
unsafe {
raw::nix_get_string(
self.context.ptr(),
value.raw_ptr(),
Some(callback_get_vec_u8),
&mut raw_buffer as *mut Vec<u8> as *mut std::ffi::c_void,
)
};
self.context.check_err()?;
let cstring = unsafe { std::ffi::CStr::from_ptr(c_str_raw) };
let str = cstring
.to_str()
.map_err(|e| anyhow::format_err!("Nix string is not valid UTF-8: {}", e))?;
Ok(str.to_owned())
String::from_utf8(raw_buffer)
.map_err(|e| anyhow::format_err!("Nix string is not valid UTF-8: {}", e))
}
/// NOTE: this will be replaced by two methods, one that also returns the context, and one that checks that the context is empty
pub fn require_string(&self, value: &Value) -> Result<String> {

View file

@ -83,7 +83,7 @@ impl Store {
raw::nix_store_get_uri(
self.context.ptr(),
self.inner.ptr(),
callback_get_vec_u8 as *mut std::ffi::c_void,
Some(callback_get_vec_u8),
&mut raw_buffer as *mut Vec<u8> as *mut std::ffi::c_void,
)
};