From d40bbbed888f79f839f51091249cc1a50010a75e Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Tue, 26 Nov 2024 13:58:04 +0100 Subject: [PATCH] maint: Update Nix (cherry picked from commit 203f5d519369235097fef2bdaefa6b3d0f5e963b) --- flake.lock | 8 ++++---- flake.nix | 2 +- rust/Cargo.lock | 15 +++++++++++++++ rust/Cargo.toml | 1 + rust/nix-c-raw/build.rs | 4 ++-- rust/nix-c-raw/include/nix-c-raw.h | 1 + rust/nix-expr/src/primop.rs | 2 +- rust/nix-flake/Cargo.toml | 18 ++++++++++++++++++ rust/nix-flake/src/lib.rs | 26 ++++++++++++++++++++++++++ rust/nix-util/src/context.rs | 10 +++++----- 10 files changed, 74 insertions(+), 13 deletions(-) create mode 100644 rust/nix-flake/Cargo.toml create mode 100644 rust/nix-flake/src/lib.rs diff --git a/flake.lock b/flake.lock index e480107..3dbe5a6 100644 --- a/flake.lock +++ b/flake.lock @@ -156,17 +156,17 @@ "pre-commit-hooks": "pre-commit-hooks" }, "locked": { - "lastModified": 1719448136, - "narHash": "sha256-ya0iofP+QysNzN7Gx7Btfe83ZW1YLpSdkccUNMnbBFQ=", + "lastModified": 1732892090, + "narHash": "sha256-Ka/uNdaqpTAiVL++4MPHg8fG5o1tiJeY6G2t5UiKhd8=", "owner": "NixOS", "repo": "nix", - "rev": "ed129267dcd7dd2cce48c09b17aefd6cfc488bcd", + "rev": "64000481168d1da9d2519f055dd1fdee22275c21", "type": "github" }, "original": { "owner": "NixOS", + "ref": "master", "repo": "nix", - "rev": "ed129267dcd7dd2cce48c09b17aefd6cfc488bcd", "type": "github" } }, diff --git a/flake.nix b/flake.nix index 04452e2..63d7b5a 100644 --- a/flake.nix +++ b/flake.nix @@ -3,7 +3,7 @@ inputs = { flake-parts.url = "github:hercules-ci/flake-parts"; - nix.url = "github:NixOS/nix/ed129267dcd7dd2cce48c09b17aefd6cfc488bcd"; # 2.24-pre, before splitting libnixflake + nix.url = "github:NixOS/nix/master"; nix.inputs.nixpkgs.follows = "nixpkgs"; nix-cargo-integration.url = "github:yusdacra/nix-cargo-integration"; nix-cargo-integration.inputs.nixpkgs.follows = "nixpkgs"; diff --git a/rust/Cargo.lock b/rust/Cargo.lock index a3d37de..c6ce2f5 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -323,6 +323,21 @@ dependencies = [ "tempfile", ] +[[package]] +name = "nix-flake" +version = "0.1.0" +dependencies = [ + "anyhow", + "cstr", + "ctor", + "lazy_static", + "nix-c-raw", + "nix-expr", + "nix-store", + "nix-util", + "tempfile", +] + [[package]] name = "nix-store" version = "0.1.0" diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 011675b..d234fbd 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -1,6 +1,7 @@ [workspace] members = [ "nix-c-raw", + "nix-flake", "nix-expr", "nix-util", "nix-store", diff --git a/rust/nix-c-raw/build.rs b/rust/nix-c-raw/build.rs index 541ea9a..5f9f7b0 100644 --- a/rust/nix-c-raw/build.rs +++ b/rust/nix-c-raw/build.rs @@ -13,7 +13,7 @@ impl bindgen::callbacks::ParseCallbacks for StripNixPrefix { fn main() { // Tell cargo to invalidate the built crate whenever the wrapper changes println!("cargo:rerun-if-changed=include/nix-c-raw.h"); - // println!("cargo:rustc-link-lib=nixflake"); + println!("cargo:rustc-link-lib=nixflake"); // https://rust-lang.github.io/rust-bindgen/library-usage.html let bindings = bindgen::Builder::default() @@ -39,7 +39,7 @@ fn main() { fn c_headers() -> Vec { let mut args = Vec::new(); // args.push("-isystem".to_string()); - for path in pkg_config::probe_library("nix-expr-c") + for path in pkg_config::probe_library("nix-flake-c") .unwrap() .include_paths .iter() diff --git a/rust/nix-c-raw/include/nix-c-raw.h b/rust/nix-c-raw/include/nix-c-raw.h index 14fb03c..88e252f 100644 --- a/rust/nix-c-raw/include/nix-c-raw.h +++ b/rust/nix-c-raw/include/nix-c-raw.h @@ -4,3 +4,4 @@ #include #include #include +#include diff --git a/rust/nix-expr/src/primop.rs b/rust/nix-expr/src/primop.rs index 9641abe..9234954 100644 --- a/rust/nix-expr/src/primop.rs +++ b/rust/nix-expr/src/primop.rs @@ -114,7 +114,7 @@ unsafe extern "C" fn function_adapter( CString::new("") .unwrap() }); - raw::set_err_msg(context_out, raw::NIX_ERR_UNKNOWN, cstr.as_ptr()); + raw::set_err_msg(context_out, raw::err_NIX_ERR_UNKNOWN, cstr.as_ptr()); }, } } diff --git a/rust/nix-flake/Cargo.toml b/rust/nix-flake/Cargo.toml new file mode 100644 index 0000000..c2328ce --- /dev/null +++ b/rust/nix-flake/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "nix-flake" +version = "0.1.0" +edition = "2021" + +[lib] +path = "src/lib.rs" + +[dependencies] +anyhow = "1.0.79" +nix-expr = { path = "../nix-expr" } +nix-store = { path = "../nix-store" } +nix-util = { path = "../nix-util" } +nix-c-raw = { path = "../nix-c-raw" } +lazy_static = "1.4.0" +ctor = "0.2.7" +tempfile = "3.10.1" +cstr = "0.2.12" diff --git a/rust/nix-flake/src/lib.rs b/rust/nix-flake/src/lib.rs new file mode 100644 index 0000000..359b2c7 --- /dev/null +++ b/rust/nix-flake/src/lib.rs @@ -0,0 +1,26 @@ +use anyhow::Result; +use nix_c_raw as raw; +use nix_util::context::{self, Context}; + +pub struct FlakeSettings { + pub(crate) ptr: *mut raw::flake_settings, +} +impl Drop for FlakeSettings { + fn drop(&mut self) { + unsafe { + raw::flake_settings_free(self.ptr); + } + } +} +impl FlakeSettings { + pub fn new() -> Result { + let mut ctx = Context::new(); + let s = unsafe { context::check_call!(raw::flake_settings_new(&mut ctx)) }?; + Ok(FlakeSettings { ptr: s }) + } + pub fn init_globally(&mut self) -> Result<()> { + let mut ctx = Context::new(); + unsafe { context::check_call!(raw::flake_init_global(&mut ctx, self.ptr)) }?; + Ok(()) + } +} diff --git a/rust/nix-util/src/context.rs b/rust/nix-util/src/context.rs index dd0aecc..d4dbe94 100644 --- a/rust/nix-util/src/context.rs +++ b/rust/nix-util/src/context.rs @@ -36,7 +36,7 @@ impl Context { /// We recommend to use `check_call!` if possible. pub fn check_err(&self) -> Result<()> { let err = unsafe { raw::err_code(self.inner.as_ptr()) }; - if err != raw::NIX_OK.try_into().unwrap() { + if err != raw::err_NIX_OK.try_into().unwrap() { // msgp is a borrowed pointer (pointing into the context), so we don't need to free it let msgp = unsafe { raw::err_msg(null_mut(), self.inner.as_ptr(), null_mut()) }; // Turn the i8 pointer into a Rust string by copying @@ -50,7 +50,7 @@ impl Context { unsafe { raw::set_err_msg( self.inner.as_ptr(), - raw::NIX_OK.try_into().unwrap(), + raw::err_NIX_OK.try_into().unwrap(), b"\0".as_ptr() as *const i8, ); } @@ -69,7 +69,7 @@ impl Context { f: F, ) -> Result> { let t = f(self.ptr()); - if unsafe { raw::err_code(self.inner.as_ptr()) == raw::NIX_ERR_KEY } { + if unsafe { raw::err_code(self.inner.as_ptr()) == raw::err_NIX_ERR_KEY } { self.clear(); return Ok(None); } @@ -112,7 +112,7 @@ macro_rules! check_call_opt_key { { let ctx : &mut $crate::context::Context = $ctx; let ret = $($f)::*(ctx.ptr(), $($arg,)*); - if unsafe { raw::err_code(ctx.ptr()) == raw::NIX_ERR_KEY } { + if unsafe { raw::err_code(ctx.ptr()) == raw::err_NIX_ERR_KEY } { ctx.clear(); return Ok(None); } @@ -143,7 +143,7 @@ mod tests { unsafe { raw::set_err_msg( ctx_ptr, - raw::NIX_ERR_UNKNOWN.try_into().unwrap(), + raw::err_NIX_ERR_UNKNOWN.try_into().unwrap(), b"dummy error message\0".as_ptr() as *const i8, ); }