From 72580f5e654bf3d51ac530a3516a37cd0154f335 Mon Sep 17 00:00:00 2001 From: Artemis Tosini Date: Sat, 13 Jul 2024 22:57:02 +0000 Subject: [PATCH] support subtituting multiple outputs --- .../base/fetch_and_unpack_nix_substituter.rs | 37 +++++++++++++------ src/action/common/provision_nix.rs | 2 +- src/settings.rs | 20 ++++++---- tests/fixtures/linux/linux.json | 4 +- tests/fixtures/linux/steam-deck.json | 4 +- tests/fixtures/macos/macos.json | 4 +- 6 files changed, 48 insertions(+), 23 deletions(-) diff --git a/src/action/base/fetch_and_unpack_nix_substituter.rs b/src/action/base/fetch_and_unpack_nix_substituter.rs index 9dde86a..4b4c134 100644 --- a/src/action/base/fetch_and_unpack_nix_substituter.rs +++ b/src/action/base/fetch_and_unpack_nix_substituter.rs @@ -36,7 +36,7 @@ pub struct FetchAndUnpackNixSubstituter { substituters: Vec, /// Desired derivation output, e.g. /// `/nix/store/n50jk09x9hshwx1lh6k3qaiygc7yxbv9-lix-2.90.0-rc1` - target: StorePath, + targets: Vec, /// Destination directory, normally temporary. /// For compatibility with tarballs, files will be placed in /// the nix-/store subdirectory of the destination @@ -55,7 +55,7 @@ const STORE_DIR: &str = "/nix/store/"; impl FetchAndUnpackNixSubstituter { #[tracing::instrument(level = "debug", skip_all)] pub async fn plan( - target: PathBuf, + targets: Vec, dest: PathBuf, trusted_keys: Vec, substituters: Vec, @@ -79,9 +79,14 @@ impl FetchAndUnpackNixSubstituter { parse_ssl_cert(ssl_cert_file).await.map_err(Self::error)?; } + let targets = targets + .iter() + .map(|p| StorePath::from_path(p)) + .collect::, _>>() + .map_err(Self::error)?; + Ok(Self { - target: StorePath::from_path(&target) - .ok_or_else(|| Self::error(SubstitutionError::InvalidStorePath))?, + targets, trusted_keys: trusted_keys_parsed, dest, proxy, @@ -145,8 +150,12 @@ impl Action for FetchAndUnpackNixSubstituter { } fn tracing_synopsis(&self) -> String { format!( - "Fetch `{}` from substituters to `{}`", - self.target.full_path, + "Fetch {} from substituters to `{}`", + self.targets + .iter() + .map(|t| format!("`{}`", t.full_path)) + .collect::>() + .join(", "), self.dest.display() ) } @@ -155,7 +164,7 @@ impl Action for FetchAndUnpackNixSubstituter { let span = span!( tracing::Level::DEBUG, "fetch_and_unpack_nix_substituter", - target = tracing::field::debug(&self.target.full_path), + targets = tracing::field::debug(&self.targets), proxy = tracing::field::Empty, ssl_cert_file = tracing::field::Empty, dest = tracing::field::display(self.dest.display()), @@ -201,7 +210,7 @@ impl Action for FetchAndUnpackNixSubstituter { .map_err(|e| ActionErrorKind::CreateDirectory(nix_store_dir.clone(), e)) .map_err(Self::error)?; - let mut outputs_remaining = vec![self.target.clone()]; + let mut outputs_remaining = self.targets.clone(); let mut outputs_done = HashSet::new(); let mut reginfo = String::new(); @@ -395,8 +404,12 @@ impl StorePath { }) } - pub fn from_path(path: &Path) -> Option { - Self::from_full_path(path.to_str()?) + pub fn from_path(path: &Path) -> Result { + let path_str = path + .to_str() + .ok_or_else(|| SubstitutionError::InvalidStorePath(path.to_owned()))?; + Self::from_full_path(path_str) + .ok_or_else(|| SubstitutionError::InvalidStorePath(path.to_owned())) } pub fn from_full_name(full_name: &str) -> Option { @@ -684,8 +697,8 @@ pub enum SubstitutionError { BadNar(Url), #[error("No substituter has path {0}")] NonexistantNarInfo(String), - #[error("Invalid nix store path")] - InvalidStorePath, + #[error("Invalid nix store path {0}")] + InvalidStorePath(PathBuf), } impl From for ActionErrorKind { diff --git a/src/action/common/provision_nix.rs b/src/action/common/provision_nix.rs index 3a2062e..2d76cb3 100644 --- a/src/action/common/provision_nix.rs +++ b/src/action/common/provision_nix.rs @@ -59,7 +59,7 @@ impl ProvisionNix { let fetch_nix = if settings.use_substituters { FetchNix::FromSubstituter( FetchAndUnpackNixSubstituter::plan( - settings.substitution_target.clone(), + settings.substitution_targets.clone(), PathBuf::from(SCRATCH_DIR), settings.substituter_trusted_keys.clone(), settings.substituters.clone(), diff --git a/src/settings.rs b/src/settings.rs index b82daa0..0b3c50e 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -173,11 +173,14 @@ pub struct CommonSettings { feature = "cli", clap( long, - env = "NIX_INSTALLER_SUBSTITUTION_TARGET", - default_value = "/nix/store/rp7y16q2py2n9y19jvxkjr83lp77bh7y-lix-2.90.0" + env = "NIX_INSTALLER_SUBSTITUTION_TARGETS", + default_values = [ + "/nix/store/rp7y16q2py2n9y19jvxkjr83lp77bh7y-lix-2.90.0", + "/nix/store/26n4d7n6bm3d1kvai6zmvzx929z9q5c9-nss-cacert-3.98", + ] ) )] - pub substitution_target: PathBuf, + pub substitution_targets: Vec, /// Download Lix from a substituter instead of an install tarball #[cfg_attr(feature = "cli", clap(long, env = "NIX_INSTALLER_USE_SUBSTITUTER"))] @@ -334,7 +337,10 @@ impl CommonSettings { .iter() .map(|s| s.to_string()) .collect(), - substitution_target: "/nix/store/rp7y16q2py2n9y19jvxkjr83lp77bh7y-lix-2.90.0".into(), + substitution_targets: vec![ + "/nix/store/rp7y16q2py2n9y19jvxkjr83lp77bh7y-lix-2.90.0".into(), + "/nix/store/26n4d7n6bm3d1kvai6zmvzx929z9q5c9-nss-cacert-3.98".into(), + ], use_substituters: false, nix_package_url: url.parse()?, proxy: Default::default(), @@ -356,7 +362,7 @@ impl CommonSettings { nix_build_user_count, substituters, substituter_trusted_keys, - substitution_target, + substitution_targets, use_substituters, nix_package_url, proxy, @@ -397,8 +403,8 @@ impl CommonSettings { serde_json::to_value(substituter_trusted_keys)?, ); map.insert( - "substitution_target".into(), - serde_json::to_value(substitution_target)?, + "substitution_targets".into(), + serde_json::to_value(substitution_targets)?, ); map.insert( "use_substituters".into(), diff --git a/tests/fixtures/linux/linux.json b/tests/fixtures/linux/linux.json index 11bd750..ca01ac4 100644 --- a/tests/fixtures/linux/linux.json +++ b/tests/fixtures/linux/linux.json @@ -419,7 +419,9 @@ "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=", "cache.lix.systems:aBnZUw8zA7H35Cz2RyKFVs3H4PlGTLawyY5KRbvJR8o=" ], - "substitution_target": "/nix/store/rp7y16q2py2n9y19jvxkjr83lp77bh7y-lix-2.90.0", + "substitution_targets": [ + "/nix/store/rp7y16q2py2n9y19jvxkjr83lp77bh7y-lix-2.90.0" + ], "use_substituters": false, "nix_package_url": { "Url": "https://releases.nixos.org/nix/nix-2.17.0/nix-2.17.0-x86_64-linux.tar.xz" diff --git a/tests/fixtures/linux/steam-deck.json b/tests/fixtures/linux/steam-deck.json index 6a294a3..b9337ea 100644 --- a/tests/fixtures/linux/steam-deck.json +++ b/tests/fixtures/linux/steam-deck.json @@ -403,7 +403,9 @@ "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=", "cache.lix.systems:aBnZUw8zA7H35Cz2RyKFVs3H4PlGTLawyY5KRbvJR8o=" ], - "substitution_target": "/nix/store/rp7y16q2py2n9y19jvxkjr83lp77bh7y-lix-2.90.0", + "substitution_targets": [ + "/nix/store/rp7y16q2py2n9y19jvxkjr83lp77bh7y-lix-2.90.0" + ], "use_substituters": false, "nix_package_url": { "Url": "https://releases.nixos.org/nix/nix-2.17.0/nix-2.17.0-x86_64-linux.tar.xz" diff --git a/tests/fixtures/macos/macos.json b/tests/fixtures/macos/macos.json index 7003584..998ca2e 100644 --- a/tests/fixtures/macos/macos.json +++ b/tests/fixtures/macos/macos.json @@ -430,7 +430,9 @@ "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=", "cache.lix.systems:aBnZUw8zA7H35Cz2RyKFVs3H4PlGTLawyY5KRbvJR8o=" ], - "substitution_target": "/nix/store/rp7y16q2py2n9y19jvxkjr83lp77bh7y-lix-2.90.0", + "substitution_target": [ + "/nix/store/rp7y16q2py2n9y19jvxkjr83lp77bh7y-lix-2.90.0" + ], "use_substituters": false, "nix_package_url": { "Url": "https://releases.nixos.org/nix/nix-2.17.0/nix-2.17.0-x86_64-darwin.tar.xz"