Fix various bugs in the tests such that Lix works now

- We were looking for a top-level tarball path that looked like nix-*.
  This was invalid, since our tarballs have lix-*.
- We were looking for a store path that looked like nix-*.*.*. This was
  invalid, since ours is lix-*.*.*.

  This change accepts both.
- We also added a symlink for nix-installer and nix-installer.sh, which
  deals with the test suite being pretty tightly coupled to that path.
- We fixed a bug exposed in the tests where --no-substitute is not
  passed while self-testing builds. This seems to have been relying on
  offline detection and while it eventually passed, it was busted and
  took ages.

Change-Id: I2f497bd647ecf1db5963a4bb245279db582d2af3
This commit is contained in:
jade 2024-06-15 20:03:03 -07:00
parent 4a4f16676d
commit 0256e915e7
10 changed files with 41 additions and 36 deletions

View file

@ -95,6 +95,8 @@
}; };
postInstall = '' postInstall = ''
cp lix-installer.sh $out/bin/lix-installer.sh cp lix-installer.sh $out/bin/lix-installer.sh
ln -s lix-installer $out/bin/nix-installer
ln -s lix-installer.sh $out/bin/nix-installer.sh
''; '';
}; };
in in

View file

@ -2,7 +2,7 @@ FROM default
COPY lix-installer /lix-installer COPY lix-installer /lix-installer
RUN chmod +x /lix-installer RUN chmod +x /lix-installer
COPY binary-tarball /binary-tarball COPY binary-tarball /binary-tarball
RUN mv /binary-tarball/nix-*.tar.xz nix.tar.xz RUN mv /binary-tarball/[nl]ix-*.tar.xz nix.tar.xz
RUN /lix-installer/bin/lix-installer install linux --logger pretty --log-directive lix_installer=debug --nix-package-url file:///nix.tar.xz --init none --extra-conf "sandbox = false" --no-confirm -vvv RUN /lix-installer/bin/lix-installer install linux --logger pretty --log-directive lix_installer=debug --nix-package-url file:///nix.tar.xz --init none --extra-conf "sandbox = false" --no-confirm -vvv
ENV PATH="${PATH}:/nix/var/nix/profiles/default/bin" ENV PATH="${PATH}:/nix/var/nix/profiles/default/bin"
RUN nix-build --no-substitute -E 'derivation { name = "foo"; system = "x86_64-linux"; builder = "/bin/sh"; args = ["-c" "echo foobar > $out"]; }' RUN nix-build --no-substitute -E 'derivation { name = "foo"; system = "x86_64-linux"; builder = "/bin/sh"; args = ["-c" "echo foobar > $out"]; }'

View file

@ -576,7 +576,7 @@ let
scp -P 20022 $ssh_opts $installer/bin/lix-installer vagrant@localhost:nix-installer scp -P 20022 $ssh_opts $installer/bin/lix-installer vagrant@localhost:nix-installer
echo "Copying nix tarball..." echo "Copying nix tarball..."
scp -P 20022 $ssh_opts $binaryTarball/nix-*.tar.xz vagrant@localhost:nix.tar.xz scp -P 20022 $ssh_opts $binaryTarball/lix-*.tar.xz vagrant@localhost:nix.tar.xz
echo "Running preinstall..." echo "Running preinstall..."
$ssh "set -eux; $preinstallScript" $ssh "set -eux; $preinstallScript"

View file

@ -6,8 +6,9 @@ use std::{
use tracing::{span, Span}; use tracing::{span, Span};
use walkdir::WalkDir; use walkdir::WalkDir;
use crate::action::{ use crate::{
Action, ActionDescription, ActionError, ActionErrorKind, ActionTag, StatefulAction, action::{Action, ActionDescription, ActionError, ActionErrorKind, ActionTag, StatefulAction},
release_tarball,
}; };
pub(crate) const DEST: &str = "/nix/"; pub(crate) const DEST: &str = "/nix/";
@ -62,15 +63,9 @@ impl Action for MoveUnpackedNix {
let Self { unpacked_path } = self; let Self { unpacked_path } = self;
// This is the `nix-$VERSION` folder which unpacks from the tarball, not a nix derivation // This is the `nix-$VERSION` folder which unpacks from the tarball, not a nix derivation
let found_nix_paths = glob::glob(&format!("{}/nix-*", unpacked_path.display())) let toplevel_path =
.map_err(|e| Self::error(MoveUnpackedNixError::from(e)))? release_tarball::find_toplevel_path(&unpacked_path).map_err(Self::error)?;
.collect::<Result<Vec<_>, _>>() let src_store = toplevel_path.join("store");
.map_err(|e| Self::error(MoveUnpackedNixError::from(e)))?;
if found_nix_paths.len() != 1 {
return Err(Self::error(ActionErrorKind::MalformedBinaryTarball));
}
let found_nix_path = found_nix_paths.into_iter().next().unwrap();
let src_store = found_nix_path.join("store");
let mut src_store_listing = tokio::fs::read_dir(src_store.clone()) let mut src_store_listing = tokio::fs::read_dir(src_store.clone())
.await .await
.map_err(|e| ActionErrorKind::ReadDir(src_store.clone(), e)) .map_err(|e| ActionErrorKind::ReadDir(src_store.clone(), e))

View file

@ -2,7 +2,7 @@ use std::path::PathBuf;
use crate::{ use crate::{
action::{ActionError, ActionErrorKind, ActionTag, StatefulAction}, action::{ActionError, ActionErrorKind, ActionTag, StatefulAction},
execute_command, set_env, execute_command, release_tarball, set_env,
}; };
use glob::glob; use glob::glob;
@ -51,8 +51,10 @@ impl Action for SetupDefaultProfile {
#[tracing::instrument(level = "debug", skip_all)] #[tracing::instrument(level = "debug", skip_all)]
async fn execute(&mut self) -> Result<(), ActionError> { async fn execute(&mut self) -> Result<(), ActionError> {
// Find an `nix` package let toplevel_path =
let nix_pkg_glob = format!("{}/nix-*/store/*-nix-*.*.*", self.unpacked_path.display()); release_tarball::find_toplevel_path(&self.unpacked_path).map_err(Self::error)?;
// Find a `nix` package
let nix_pkg_glob = format!("{}/store/*-[nl]ix-*.*.*", toplevel_path.display());
let mut found_nix_pkg = None; let mut found_nix_pkg = None;
for entry in glob(&nix_pkg_glob).map_err(Self::error)? { for entry in glob(&nix_pkg_glob).map_err(Self::error)? {
match entry { match entry {
@ -78,10 +80,7 @@ impl Action for SetupDefaultProfile {
}; };
// Find an `nss-cacert` package, add it too. // Find an `nss-cacert` package, add it too.
let nss_ca_cert_pkg_glob = format!( let nss_ca_cert_pkg_glob = format!("{}/store/*-nss-cacert-*.*", toplevel_path.display());
"{}/nix-*/store/*-nss-cacert-*.*",
self.unpacked_path.display()
);
let mut found_nss_ca_cert_pkg = None; let mut found_nss_ca_cert_pkg = None;
for entry in glob(&nss_ca_cert_pkg_glob).map_err(Self::error)? { for entry in glob(&nss_ca_cert_pkg_glob).map_err(Self::error)? {
match entry { match entry {
@ -108,14 +107,8 @@ impl Action for SetupDefaultProfile {
return Err(Self::error(SetupDefaultProfileError::NoNssCacert)); return Err(Self::error(SetupDefaultProfileError::NoNssCacert));
}; };
let found_nix_paths = glob::glob(&format!("{}/nix-*", self.unpacked_path.display())) let found_nix_path =
.map_err(Self::error)? release_tarball::find_toplevel_path(&self.unpacked_path).map_err(Self::error)?;
.collect::<Result<Vec<_>, _>>()
.map_err(Self::error)?;
if found_nix_paths.len() != 1 {
return Err(Self::error(ActionErrorKind::MalformedBinaryTarball));
}
let found_nix_path = found_nix_paths.into_iter().next().unwrap();
let reginfo_path = found_nix_path.join(".reginfo"); let reginfo_path = found_nix_path.join(".reginfo");
let reginfo = tokio::fs::read(&reginfo_path) let reginfo = tokio::fs::read(&reginfo_path)
.await .await

View file

@ -488,10 +488,7 @@ pub enum ActionErrorKind {
"".to_string() "".to_string()
} }
)] )]
CommandOutput { CommandOutput { command: String, output: Output },
command: String,
output: Output,
},
#[error("Joining spawned async task")] #[error("Joining spawned async task")]
Join( Join(
#[source] #[source]
@ -509,7 +506,7 @@ pub enum ActionErrorKind {
/// A MacOS (Darwin) plist related error /// A MacOS (Darwin) plist related error
#[error(transparent)] #[error(transparent)]
Plist(#[from] plist::Error), Plist(#[from] plist::Error),
#[error("Unexpected binary tarball contents found, the build result from `https://releases.nixos.org/?prefix=nix/` or `nix build nix#hydraJobs.binaryTarball.$SYSTEM` is expected")] #[error("Unexpected binary tarball contents found, the build result from `https://releases.lix.systems/?prefix=nix/` or `nix build lix#hydraJobs.binaryTarball.$SYSTEM` is expected")]
MalformedBinaryTarball, MalformedBinaryTarball,
#[error("Could not find `{0}` in PATH; This action only works on SteamOS, which should have this present in PATH.")] #[error("Could not find `{0}` in PATH; This action only works on SteamOS, which should have this present in PATH.")]
MissingSteamosBinary(String), MissingSteamosBinary(String),

View file

@ -20,9 +20,9 @@ pub trait CommandExecute {
} }
/** /**
The Determinate Nix installer (lix variant) The Lix installer.
A fast, friendly, and reliable tool to help you use Nix with Flakes everywhere. A fast, friendly, and reliable tool to help you install CppNix or Lix on your system.
*/ */
#[derive(Debug, Parser)] #[derive(Debug, Parser)]
#[clap(version)] #[clap(version)]

View file

@ -76,6 +76,7 @@ mod error;
mod os; mod os;
mod plan; mod plan;
pub mod planner; pub mod planner;
mod release_tarball;
pub mod self_test; pub mod self_test;
pub mod settings; pub mod settings;

17
src/release_tarball.rs Normal file
View file

@ -0,0 +1,17 @@
use std::path::{Path, PathBuf};
use crate::action::ActionErrorKind;
/// Finds the top-level path in the tarball, e.g. lix-2.90.0-rc1-x86_64-linux
pub fn find_toplevel_path(unpacked_path: &Path) -> Result<PathBuf, ActionErrorKind> {
let found_nix_paths = glob::glob(&format!("{}/[nl]ix-*", unpacked_path.display()))
.map_err(ActionErrorKind::from)?
.collect::<Result<Vec<_>, _>>()
.map_err(ActionErrorKind::from)?;
if found_nix_paths.len() != 1 {
return Err(ActionErrorKind::MalformedBinaryTarball);
}
let found_nix_path = found_nix_paths.into_iter().next().unwrap();
Ok(found_nix_path)
}

View file

@ -86,7 +86,7 @@ impl Shell {
.as_millis(); .as_millis();
command.arg(format!( command.arg(format!(
r#"nix build --no-link --expr 'derivation {{ name = "self-test-{executable}-{timestamp_millis}"; system = "{SYSTEM}"; builder = "/bin/sh"; args = ["-c" "echo hello > \$out"]; }}'"# r#"nix build --no-substitute --no-link --expr 'derivation {{ name = "self-test-{executable}-{timestamp_millis}"; system = "{SYSTEM}"; builder = "/bin/sh"; args = ["-c" "echo hello > \$out"]; }}'"#
)); ));
let command_str = format!("{:?}", command.as_std()); let command_str = format!("{:?}", command.as_std());