From 0256e915e72f9fb0159eba901df9aa1af2698027 Mon Sep 17 00:00:00 2001 From: Jade Lovelace Date: Sat, 15 Jun 2024 20:03:03 -0700 Subject: [PATCH] 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 --- flake.nix | 2 ++ nix/tests/container-test/default/Dockerfile | 2 +- nix/tests/vm-test/default.nix | 2 +- src/action/base/move_unpacked_nix.rs | 17 ++++++--------- src/action/base/setup_default_profile.rs | 23 +++++++-------------- src/action/mod.rs | 7 ++----- src/cli/mod.rs | 4 ++-- src/lib.rs | 1 + src/release_tarball.rs | 17 +++++++++++++++ src/self_test.rs | 2 +- 10 files changed, 41 insertions(+), 36 deletions(-) create mode 100644 src/release_tarball.rs diff --git a/flake.nix b/flake.nix index c4fe485..edba203 100644 --- a/flake.nix +++ b/flake.nix @@ -95,6 +95,8 @@ }; postInstall = '' 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 diff --git a/nix/tests/container-test/default/Dockerfile b/nix/tests/container-test/default/Dockerfile index dcd2127..af6957c 100644 --- a/nix/tests/container-test/default/Dockerfile +++ b/nix/tests/container-test/default/Dockerfile @@ -2,7 +2,7 @@ FROM default COPY lix-installer /lix-installer RUN chmod +x /lix-installer 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 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"]; }' diff --git a/nix/tests/vm-test/default.nix b/nix/tests/vm-test/default.nix index 10e410b..f317bb5 100644 --- a/nix/tests/vm-test/default.nix +++ b/nix/tests/vm-test/default.nix @@ -576,7 +576,7 @@ let scp -P 20022 $ssh_opts $installer/bin/lix-installer vagrant@localhost:nix-installer 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..." $ssh "set -eux; $preinstallScript" diff --git a/src/action/base/move_unpacked_nix.rs b/src/action/base/move_unpacked_nix.rs index 37e034f..6493583 100644 --- a/src/action/base/move_unpacked_nix.rs +++ b/src/action/base/move_unpacked_nix.rs @@ -6,8 +6,9 @@ use std::{ use tracing::{span, Span}; use walkdir::WalkDir; -use crate::action::{ - Action, ActionDescription, ActionError, ActionErrorKind, ActionTag, StatefulAction, +use crate::{ + action::{Action, ActionDescription, ActionError, ActionErrorKind, ActionTag, StatefulAction}, + release_tarball, }; pub(crate) const DEST: &str = "/nix/"; @@ -62,15 +63,9 @@ impl Action for MoveUnpackedNix { let Self { unpacked_path } = self; // 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())) - .map_err(|e| Self::error(MoveUnpackedNixError::from(e)))? - .collect::, _>>() - .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 toplevel_path = + release_tarball::find_toplevel_path(&unpacked_path).map_err(Self::error)?; + let src_store = toplevel_path.join("store"); let mut src_store_listing = tokio::fs::read_dir(src_store.clone()) .await .map_err(|e| ActionErrorKind::ReadDir(src_store.clone(), e)) diff --git a/src/action/base/setup_default_profile.rs b/src/action/base/setup_default_profile.rs index 6a67cd3..83296bc 100644 --- a/src/action/base/setup_default_profile.rs +++ b/src/action/base/setup_default_profile.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; use crate::{ action::{ActionError, ActionErrorKind, ActionTag, StatefulAction}, - execute_command, set_env, + execute_command, release_tarball, set_env, }; use glob::glob; @@ -51,8 +51,10 @@ impl Action for SetupDefaultProfile { #[tracing::instrument(level = "debug", skip_all)] async fn execute(&mut self) -> Result<(), ActionError> { - // Find an `nix` package - let nix_pkg_glob = format!("{}/nix-*/store/*-nix-*.*.*", self.unpacked_path.display()); + let toplevel_path = + 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; for entry in glob(&nix_pkg_glob).map_err(Self::error)? { match entry { @@ -78,10 +80,7 @@ impl Action for SetupDefaultProfile { }; // Find an `nss-cacert` package, add it too. - let nss_ca_cert_pkg_glob = format!( - "{}/nix-*/store/*-nss-cacert-*.*", - self.unpacked_path.display() - ); + let nss_ca_cert_pkg_glob = format!("{}/store/*-nss-cacert-*.*", toplevel_path.display()); let mut found_nss_ca_cert_pkg = None; for entry in glob(&nss_ca_cert_pkg_glob).map_err(Self::error)? { match entry { @@ -108,14 +107,8 @@ impl Action for SetupDefaultProfile { return Err(Self::error(SetupDefaultProfileError::NoNssCacert)); }; - let found_nix_paths = glob::glob(&format!("{}/nix-*", self.unpacked_path.display())) - .map_err(Self::error)? - .collect::, _>>() - .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 found_nix_path = + release_tarball::find_toplevel_path(&self.unpacked_path).map_err(Self::error)?; let reginfo_path = found_nix_path.join(".reginfo"); let reginfo = tokio::fs::read(®info_path) .await diff --git a/src/action/mod.rs b/src/action/mod.rs index 11ddc53..8483748 100644 --- a/src/action/mod.rs +++ b/src/action/mod.rs @@ -488,10 +488,7 @@ pub enum ActionErrorKind { "".to_string() } )] - CommandOutput { - command: String, - output: Output, - }, + CommandOutput { command: String, output: Output }, #[error("Joining spawned async task")] Join( #[source] @@ -509,7 +506,7 @@ pub enum ActionErrorKind { /// A MacOS (Darwin) plist related error #[error(transparent)] 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, #[error("Could not find `{0}` in PATH; This action only works on SteamOS, which should have this present in PATH.")] MissingSteamosBinary(String), diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 89eb090..493491d 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -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)] #[clap(version)] diff --git a/src/lib.rs b/src/lib.rs index 21d5015..59349e4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -76,6 +76,7 @@ mod error; mod os; mod plan; pub mod planner; +mod release_tarball; pub mod self_test; pub mod settings; diff --git a/src/release_tarball.rs b/src/release_tarball.rs new file mode 100644 index 0000000..ef915c4 --- /dev/null +++ b/src/release_tarball.rs @@ -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 { + let found_nix_paths = glob::glob(&format!("{}/[nl]ix-*", unpacked_path.display())) + .map_err(ActionErrorKind::from)? + .collect::, _>>() + .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) +} diff --git a/src/self_test.rs b/src/self_test.rs index 0615b19..c3456a6 100644 --- a/src/self_test.rs +++ b/src/self_test.rs @@ -86,7 +86,7 @@ impl Shell { .as_millis(); 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());