Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
nix.url = "github:DeterminateSystems/nix-src";
nix.url = "github:DeterminateSystems/nix-src/tristanross/dsp-62-collab-figure-out-static-building-of-determinate-nix";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this PR depend on this branch, or were you just playing with it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depends on it for the nix_libfetchers_init function.

nix-cargo-integration.url = "github:90-008/nix-cargo-integration";
nix-cargo-integration.inputs.nixpkgs.follows = "nixpkgs";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
Expand Down
1 change: 0 additions & 1 deletion nix-bindings-expr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ nix-bindings-bdwgc-sys = { path = "../nix-bindings-bdwgc-sys", version = "0.2.1"
nix-bindings-util-sys = { path = "../nix-bindings-util-sys", version = "0.2.1" }
nix-bindings-store-sys = { path = "../nix-bindings-store-sys", version = "0.2.1" }
nix-bindings-expr-sys = { path = "../nix-bindings-expr-sys", version = "0.2.1" }
lazy_static = "1.4"
ctor = "0.2"
tempfile = "3.10"
cstr = "0.2"
Expand Down
17 changes: 6 additions & 11 deletions nix-bindings-expr/src/eval_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ use crate::value::{Int, Value, ValueType};
use anyhow::Context as _;
use anyhow::{bail, Result};
use cstr::cstr;
use lazy_static::lazy_static;
use nix_bindings_bdwgc_sys as gc;
use nix_bindings_expr_sys as raw;
use nix_bindings_store::path::StorePath;
Expand All @@ -148,17 +147,13 @@ use std::ffi::{c_char, CString};
use std::iter::FromIterator;
use std::os::raw::c_uint;
use std::ptr::{null, null_mut, NonNull};
use std::sync::{Arc, Weak};
use std::sync::{Arc, LazyLock, Weak};

lazy_static! {
static ref INIT: Result<()> = {
unsafe {
gc::GC_allow_register_threads();
check_call!(raw::libexpr_init(&mut Context::new()))?;
Ok(())
}
};
}
static INIT: LazyLock<Result<()>> = LazyLock::new(|| unsafe {
gc::GC_allow_register_threads();
check_call!(raw::libexpr_init(&mut Context::new()))?;
Ok(())
});

pub fn init() -> Result<()> {
let x = INIT.as_ref();
Expand Down
23 changes: 23 additions & 0 deletions nix-bindings-fetchers/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
use anyhow::{Context as _, Result};
use nix_bindings_fetchers_sys as raw;
use nix_bindings_util::check_call;
use nix_bindings_util::context::{self, Context};
use std::ptr::NonNull;
use std::sync::LazyLock;

static INIT: LazyLock<Result<()>> = LazyLock::new(|| unsafe {
check_call!(raw::libfetchers_init(&mut Context::new()))?;
Ok(())
});

pub fn init() -> Result<()> {
let x = INIT.as_ref();
match x {
Ok(_) => Ok(()),
Err(e) => {
// Couldn't just clone the error, so we have to print it here.
Err(anyhow::format_err!(
"nix_bindings_fetchers::init error: {}",
e
))
}
}
}

pub struct FetchersSettings {
pub(crate) ptr: NonNull<raw::fetchers_settings>,
Expand All @@ -15,6 +36,8 @@ impl Drop for FetchersSettings {
}
impl FetchersSettings {
pub fn new() -> Result<Self> {
init()?;

let mut ctx = Context::new();
let ptr = unsafe { context::check_call!(raw::fetchers_settings_new(&mut ctx))? };
Ok(FetchersSettings {
Expand Down
1 change: 0 additions & 1 deletion nix-bindings-flake/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ nix-bindings-fetchers = { path = "../nix-bindings-fetchers", version = "0.2.1" }
nix-bindings-store = { path = "../nix-bindings-store", version = "0.2.1" }
nix-bindings-util = { path = "../nix-bindings-util", version = "0.2.1" }
nix-bindings-flake-sys = { path = "../nix-bindings-flake-sys", version = "0.2.1" }
lazy_static = "1.4"
ctor = "0.2"
tempfile = "3.10"
cstr = "0.2"
Expand Down
1 change: 0 additions & 1 deletion nix-bindings-store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ anyhow = "1.0"
nix-bindings-util = { path = "../nix-bindings-util", version = "0.2.1" }
nix-bindings-util-sys = { path = "../nix-bindings-util-sys", version = "0.2.1" }
nix-bindings-store-sys = { path = "../nix-bindings-store-sys", version = "0.2.1" }
lazy_static = "1.4"
zerocopy = "0.8"
harmonia-store-core = { version = "0.0.0-alpha.0", optional = true }
serde_json = { version = "1.0", optional = true }
Expand Down
18 changes: 7 additions & 11 deletions nix-bindings-store/src/store.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use anyhow::{bail, Error, Result};
use lazy_static::lazy_static;
use nix_bindings_store_sys as raw;
use nix_bindings_util::context::Context;
use nix_bindings_util::string_return::{
Expand All @@ -13,19 +12,17 @@ use std::collections::HashMap;
use std::ffi::{c_char, CStr, CString};
use std::ptr::null_mut;
use std::ptr::NonNull;
use std::sync::{Arc, Mutex, Weak};
use std::sync::{Arc, LazyLock, Mutex, Weak};

#[cfg(nix_at_least = "2.31")]
use crate::derivation::Derivation;
use crate::path::StorePath;

/* TODO make Nix itself thread safe */
lazy_static! {
static ref INIT: Result<()> = unsafe {
check_call!(raw::libstore_init(&mut Context::new()))?;
Ok(())
};
}
static INIT: LazyLock<Result<()>> = LazyLock::new(|| unsafe {
check_call!(raw::libstore_init(&mut Context::new()))?;
Ok(())
});

struct StoreRef {
inner: NonNull<raw::Store>,
Expand Down Expand Up @@ -68,9 +65,8 @@ impl StoreWeak {
/// Protects against https://github.com/NixOS/nix/issues/11979 (unless different parameters are passed, in which case it's up to luck, but you do get your own parameters as you asked for).
type StoreCacheMap = HashMap<(Option<String>, Vec<(String, String)>), StoreWeak>;

lazy_static! {
static ref STORE_CACHE: Arc<Mutex<StoreCacheMap>> = Arc::new(Mutex::new(HashMap::new()));
}
static STORE_CACHE: LazyLock<Arc<Mutex<StoreCacheMap>>> =
LazyLock::new(|| Arc::new(Mutex::new(HashMap::new())));

#[cfg(nix_at_least = "2.31")]
unsafe extern "C" fn callback_get_result_store_path_set(
Expand Down