diff options
author | Vova Kryachko <v.kryachko@gmail.com> | 2024-11-12T14·54-0500 |
---|---|---|
committer | Vladimir Kryachko <v.kryachko@gmail.com> | 2024-11-12T16·43+0000 |
commit | 6aada9106209d431407c3a45f466ef59b3cff504 (patch) | |
tree | 658d5a673f4f5011db4bebe1cc43aa37bfdeff02 /tvix/store | |
parent | b1764e11092f7817633ae013508e6285585ac1cf (diff) |
feat(tvix-store): Improve tvix-store copy. r/8916
This change contains 2 improvements to the tvix-store copy command: 1. Allows reading the reference graph from stdin, using `-` argument 2. Supports json representation produced by `nix path-info --json` command. In general it makes is easier and faster to import arbitrary closures from an existing nix store with e.g the following command: ``` nix path-info ./result --json --closure-size --recursive | \ jq -s '{closure: add}' | \ tvix-store copy - ``` Change-Id: Id6eea2993da233ecfbdc186f1a8c37735b686264 Reviewed-on: https://cl.tvl.fyi/c/depot/+/12765 Tested-by: BuildkiteCI Reviewed-by: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix/store')
-rw-r--r-- | tvix/store/src/bin/tvix-store.rs | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/tvix/store/src/bin/tvix-store.rs b/tvix/store/src/bin/tvix-store.rs index 75f1ec11d56e..764b327a43c6 100644 --- a/tvix/store/src/bin/tvix-store.rs +++ b/tvix/store/src/bin/tvix-store.rs @@ -85,10 +85,18 @@ enum Commands { #[clap(flatten)] service_addrs: ServiceUrlsGrpc, - /// A path pointing to a JSON file produced by the Nix + /// A path pointing to a JSON file(or '-' for stdin) produced by the Nix /// `__structuredAttrs` containing reference graph information provided /// by the `exportReferencesGraph` feature. /// + /// Additionally supports the output from the following nix command: + /// + /// ```notrust + /// nix path-info --json --closure-size --recursive <some-path> | \ + /// jq -s '{closure: add}' | \ + /// tvix-store copy - + /// ``` + /// /// This can be used to invoke tvix-store inside a Nix derivation /// copying to a Tvix store (or outside, if the JSON file is copied /// out). @@ -348,9 +356,14 @@ async fn run_cli( } => { let (blob_service, directory_service, path_info_service, _nar_calculation_service) = tvix_store::utils::construct_services(service_addrs).await?; - // Parse the file at reference_graph_path. - let reference_graph_json = tokio::fs::read(&reference_graph_path).await?; + let reference_graph_json = if reference_graph_path == PathBuf::from("-") { + let mut writer: Vec<u8> = vec![]; + tokio::io::copy(&mut tokio::io::stdin(), &mut writer).await?; + writer + } else { + tokio::fs::read(&reference_graph_path).await? + }; #[derive(Deserialize, Serialize)] struct ReferenceGraph<'a> { @@ -430,8 +443,8 @@ async fn run_cli( references: elem.references.iter().map(StorePath::to_owned).collect(), nar_size: elem.nar_size, nar_sha256: elem.nar_sha256, - signatures: vec![], - deriver: None, + signatures: elem.signatures.iter().map(|s| s.to_owned()).collect(), + deriver: elem.deriver.map(|p| p.to_owned()), ca: None, }; |