forked from lix-project/lix-installer
support subtituting multiple outputs
This commit is contained in:
parent
0dda2cde4d
commit
72580f5e65
|
@ -36,7 +36,7 @@ pub struct FetchAndUnpackNixSubstituter {
|
|||
substituters: Vec<Url>,
|
||||
/// Desired derivation output, e.g.
|
||||
/// `/nix/store/n50jk09x9hshwx1lh6k3qaiygc7yxbv9-lix-2.90.0-rc1`
|
||||
target: StorePath,
|
||||
targets: Vec<StorePath>,
|
||||
/// 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<PathBuf>,
|
||||
dest: PathBuf,
|
||||
trusted_keys: Vec<String>,
|
||||
substituters: Vec<Url>,
|
||||
|
@ -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::<Result<Vec<_>, _>>()
|
||||
.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::<Vec<String>>()
|
||||
.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> {
|
||||
Self::from_full_path(path.to_str()?)
|
||||
pub fn from_path(path: &Path) -> Result<Self, SubstitutionError> {
|
||||
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> {
|
||||
|
@ -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<SubstitutionError> for ActionErrorKind {
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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<PathBuf>,
|
||||
|
||||
/// 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(),
|
||||
|
|
4
tests/fixtures/linux/linux.json
vendored
4
tests/fixtures/linux/linux.json
vendored
|
@ -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"
|
||||
|
|
4
tests/fixtures/linux/steam-deck.json
vendored
4
tests/fixtures/linux/steam-deck.json
vendored
|
@ -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"
|
||||
|
|
4
tests/fixtures/macos/macos.json
vendored
4
tests/fixtures/macos/macos.json
vendored
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue