support subtituting multiple outputs

This commit is contained in:
Artemis Tosini 2024-07-13 22:57:02 +00:00
parent 0dda2cde4d
commit 72580f5e65
Signed by: artemist
GPG key ID: EE5227935FE3FF18
6 changed files with 48 additions and 23 deletions

View file

@ -36,7 +36,7 @@ pub struct FetchAndUnpackNixSubstituter {
substituters: Vec<Url>, substituters: Vec<Url>,
/// Desired derivation output, e.g. /// Desired derivation output, e.g.
/// `/nix/store/n50jk09x9hshwx1lh6k3qaiygc7yxbv9-lix-2.90.0-rc1` /// `/nix/store/n50jk09x9hshwx1lh6k3qaiygc7yxbv9-lix-2.90.0-rc1`
target: StorePath, targets: Vec<StorePath>,
/// Destination directory, normally temporary. /// Destination directory, normally temporary.
/// For compatibility with tarballs, files will be placed in /// For compatibility with tarballs, files will be placed in
/// the nix-/store subdirectory of the destination /// the nix-/store subdirectory of the destination
@ -55,7 +55,7 @@ const STORE_DIR: &str = "/nix/store/";
impl FetchAndUnpackNixSubstituter { impl FetchAndUnpackNixSubstituter {
#[tracing::instrument(level = "debug", skip_all)] #[tracing::instrument(level = "debug", skip_all)]
pub async fn plan( pub async fn plan(
target: PathBuf, targets: Vec<PathBuf>,
dest: PathBuf, dest: PathBuf,
trusted_keys: Vec<String>, trusted_keys: Vec<String>,
substituters: Vec<Url>, substituters: Vec<Url>,
@ -79,9 +79,14 @@ impl FetchAndUnpackNixSubstituter {
parse_ssl_cert(ssl_cert_file).await.map_err(Self::error)?; parse_ssl_cert(ssl_cert_file).await.map_err(Self::error)?;
} }
let targets = targets
.iter()
.map(|p| StorePath::from_path(p))
.collect::<Result<Vec<_>, _>>()
.map_err(Self::error)?;
Ok(Self { Ok(Self {
target: StorePath::from_path(&target) targets,
.ok_or_else(|| Self::error(SubstitutionError::InvalidStorePath))?,
trusted_keys: trusted_keys_parsed, trusted_keys: trusted_keys_parsed,
dest, dest,
proxy, proxy,
@ -145,8 +150,12 @@ impl Action for FetchAndUnpackNixSubstituter {
} }
fn tracing_synopsis(&self) -> String { fn tracing_synopsis(&self) -> String {
format!( format!(
"Fetch `{}` from substituters to `{}`", "Fetch {} from substituters to `{}`",
self.target.full_path, self.targets
.iter()
.map(|t| format!("`{}`", t.full_path))
.collect::<Vec<String>>()
.join(", "),
self.dest.display() self.dest.display()
) )
} }
@ -155,7 +164,7 @@ impl Action for FetchAndUnpackNixSubstituter {
let span = span!( let span = span!(
tracing::Level::DEBUG, tracing::Level::DEBUG,
"fetch_and_unpack_nix_substituter", "fetch_and_unpack_nix_substituter",
target = tracing::field::debug(&self.target.full_path), targets = tracing::field::debug(&self.targets),
proxy = tracing::field::Empty, proxy = tracing::field::Empty,
ssl_cert_file = tracing::field::Empty, ssl_cert_file = tracing::field::Empty,
dest = tracing::field::display(self.dest.display()), 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(|e| ActionErrorKind::CreateDirectory(nix_store_dir.clone(), e))
.map_err(Self::error)?; .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 outputs_done = HashSet::new();
let mut reginfo = String::new(); let mut reginfo = String::new();
@ -395,8 +404,12 @@ impl StorePath {
}) })
} }
pub fn from_path(path: &Path) -> Option<Self> { pub fn from_path(path: &Path) -> Result<Self, SubstitutionError> {
Self::from_full_path(path.to_str()?) 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<Self> { pub fn from_full_name(full_name: &str) -> Option<Self> {
@ -684,8 +697,8 @@ pub enum SubstitutionError {
BadNar(Url), BadNar(Url),
#[error("No substituter has path {0}")] #[error("No substituter has path {0}")]
NonexistantNarInfo(String), NonexistantNarInfo(String),
#[error("Invalid nix store path")] #[error("Invalid nix store path {0}")]
InvalidStorePath, InvalidStorePath(PathBuf),
} }
impl From<SubstitutionError> for ActionErrorKind { impl From<SubstitutionError> for ActionErrorKind {

View file

@ -59,7 +59,7 @@ impl ProvisionNix {
let fetch_nix = if settings.use_substituters { let fetch_nix = if settings.use_substituters {
FetchNix::FromSubstituter( FetchNix::FromSubstituter(
FetchAndUnpackNixSubstituter::plan( FetchAndUnpackNixSubstituter::plan(
settings.substitution_target.clone(), settings.substitution_targets.clone(),
PathBuf::from(SCRATCH_DIR), PathBuf::from(SCRATCH_DIR),
settings.substituter_trusted_keys.clone(), settings.substituter_trusted_keys.clone(),
settings.substituters.clone(), settings.substituters.clone(),

View file

@ -173,11 +173,14 @@ pub struct CommonSettings {
feature = "cli", feature = "cli",
clap( clap(
long, long,
env = "NIX_INSTALLER_SUBSTITUTION_TARGET", env = "NIX_INSTALLER_SUBSTITUTION_TARGETS",
default_value = "/nix/store/rp7y16q2py2n9y19jvxkjr83lp77bh7y-lix-2.90.0" default_values = [
"/nix/store/rp7y16q2py2n9y19jvxkjr83lp77bh7y-lix-2.90.0",
"/nix/store/26n4d7n6bm3d1kvai6zmvzx929z9q5c9-nss-cacert-3.98",
]
) )
)] )]
pub substitution_target: PathBuf, pub substitution_targets: Vec<PathBuf>,
/// Download Lix from a substituter instead of an install tarball /// Download Lix from a substituter instead of an install tarball
#[cfg_attr(feature = "cli", clap(long, env = "NIX_INSTALLER_USE_SUBSTITUTER"))] #[cfg_attr(feature = "cli", clap(long, env = "NIX_INSTALLER_USE_SUBSTITUTER"))]
@ -334,7 +337,10 @@ impl CommonSettings {
.iter() .iter()
.map(|s| s.to_string()) .map(|s| s.to_string())
.collect(), .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, use_substituters: false,
nix_package_url: url.parse()?, nix_package_url: url.parse()?,
proxy: Default::default(), proxy: Default::default(),
@ -356,7 +362,7 @@ impl CommonSettings {
nix_build_user_count, nix_build_user_count,
substituters, substituters,
substituter_trusted_keys, substituter_trusted_keys,
substitution_target, substitution_targets,
use_substituters, use_substituters,
nix_package_url, nix_package_url,
proxy, proxy,
@ -397,8 +403,8 @@ impl CommonSettings {
serde_json::to_value(substituter_trusted_keys)?, serde_json::to_value(substituter_trusted_keys)?,
); );
map.insert( map.insert(
"substitution_target".into(), "substitution_targets".into(),
serde_json::to_value(substitution_target)?, serde_json::to_value(substitution_targets)?,
); );
map.insert( map.insert(
"use_substituters".into(), "use_substituters".into(),

View file

@ -419,7 +419,9 @@
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=", "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=",
"cache.lix.systems:aBnZUw8zA7H35Cz2RyKFVs3H4PlGTLawyY5KRbvJR8o=" "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, "use_substituters": false,
"nix_package_url": { "nix_package_url": {
"Url": "https://releases.nixos.org/nix/nix-2.17.0/nix-2.17.0-x86_64-linux.tar.xz" "Url": "https://releases.nixos.org/nix/nix-2.17.0/nix-2.17.0-x86_64-linux.tar.xz"

View file

@ -403,7 +403,9 @@
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=", "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=",
"cache.lix.systems:aBnZUw8zA7H35Cz2RyKFVs3H4PlGTLawyY5KRbvJR8o=" "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, "use_substituters": false,
"nix_package_url": { "nix_package_url": {
"Url": "https://releases.nixos.org/nix/nix-2.17.0/nix-2.17.0-x86_64-linux.tar.xz" "Url": "https://releases.nixos.org/nix/nix-2.17.0/nix-2.17.0-x86_64-linux.tar.xz"

View file

@ -430,7 +430,9 @@
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=", "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=",
"cache.lix.systems:aBnZUw8zA7H35Cz2RyKFVs3H4PlGTLawyY5KRbvJR8o=" "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, "use_substituters": false,
"nix_package_url": { "nix_package_url": {
"Url": "https://releases.nixos.org/nix/nix-2.17.0/nix-2.17.0-x86_64-darwin.tar.xz" "Url": "https://releases.nixos.org/nix/nix-2.17.0/nix-2.17.0-x86_64-darwin.tar.xz"