mod common;
use std::path::PathBuf;
fn nix_repo() -> PathBuf {
common::pleme_io_root().join("nix")
}
#[test]
fn nix_repo_eval_no_crash() {
if common::skip_if_offline("system_eval") {
return;
}
let dir = nix_repo();
if !dir.join("flake.nix").exists() {
println!("skip: nix repo not found at {}", dir.display());
return;
}
println!("evaluating {}", dir.display());
match sui_eval::builtins::evaluate_flake(&dir) {
Ok(v) => {
if let sui_eval::value::Value::Attrs(ref attrs) = v {
let keys: Vec<String> = attrs.keys().collect();
println!("top-level keys: {keys:?}");
}
panic!(
"TRIPWIRE: sui evaluated the pleme-io/nix flake. This is GOOD NEWS \
and the test is red on purpose — theory/BALIZA.md §III records \
system-toplevel eval as ABSENT (zero recorded instances, ever), \
and phases 8/9/10 are written on that premise. Re-measure, update \
BALIZA.md §III, then replace this tripwire with the positive \
assertion in the same commit."
);
}
Err(e) => {
println!("still absent (expected): {e}");
}
}
}
#[test]
fn nix_repo_has_darwin_configurations() {
if common::skip_if_offline("system_eval_darwin") {
return;
}
let dir = nix_repo();
if !dir.join("flake.nix").exists() {
return;
}
let result = match sui_eval::builtins::evaluate_flake(&dir) {
Ok(v) => v,
Err(e) => {
println!("eval failed: {e}");
return;
}
};
if let sui_eval::value::Value::Attrs(ref attrs) = result {
assert!(
attrs.contains_key("darwinConfigurations"),
"flake output should have darwinConfigurations"
);
println!("darwinConfigurations found");
if let Some(dc) = attrs.get("darwinConfigurations") {
let forced = sui_eval::eval::force_value(dc);
match forced {
Ok(sui_eval::value::Value::Attrs(ref dc_attrs)) => {
let hosts: Vec<String> = dc_attrs.keys().collect();
println!("hosts: {:?}", hosts);
}
Ok(other) => println!("darwinConfigurations is {}", other.type_name()),
Err(e) => println!("force darwinConfigurations: {e}"),
}
}
}
}
#[test]
fn nix_repo_darwin_cid_exists() {
if common::skip_if_offline("system_eval_cid") {
return;
}
let dir = nix_repo();
if !dir.join("flake.nix").exists() {
return;
}
let result = match sui_eval::builtins::evaluate_flake(&dir) {
Ok(v) => v,
Err(e) => {
println!("eval failed: {e}");
return;
}
};
let path = ["darwinConfigurations", "cid"];
let mut current = result;
for key in &path {
current = match sui_eval::eval::force_value(¤t) {
Ok(v) => v,
Err(e) => {
println!("force at {key}: {e}");
return;
}
};
match current {
sui_eval::value::Value::Attrs(ref attrs) => {
current = match attrs.get(*key) {
Some(v) => v.clone(),
None => {
println!("{key} not found");
return;
}
};
}
_ => {
println!("expected attrs at {key}, got {}", current.type_name());
return;
}
}
}
println!("darwinConfigurations.cid reached successfully");
}
#[test]
fn nix_repo_cid_drv_path() {
if common::skip_if_offline("system_eval_drv") {
return;
}
let dir = nix_repo();
if !dir.join("flake.nix").exists() {
return;
}
let result = match sui_eval::builtins::evaluate_flake(&dir) {
Ok(v) => v,
Err(e) => {
println!("eval failed: {e}");
return;
}
};
let path = [
"darwinConfigurations",
"cid",
"config",
"system",
"build",
"toplevel",
"drvPath",
];
let mut current = result;
for key in &path {
current = match sui_eval::eval::force_value(¤t) {
Ok(v) => v,
Err(e) => {
println!("force at {key}: {e}");
return;
}
};
match current {
sui_eval::value::Value::Attrs(ref attrs) => {
current = match attrs.get(*key) {
Some(v) => v.clone(),
None => {
println!("{key} not found in attrs");
return;
}
};
}
_ => {
println!("expected attrs at {key}, got {}", current.type_name());
return;
}
}
}
let forced = sui_eval::eval::force_value(¤t);
match forced {
Ok(sui_eval::value::Value::String(ref s)) => {
println!("drvPath: {}", s.as_str());
assert!(
s.as_str().starts_with("/nix/store/"),
"drvPath should be a store path"
);
assert!(s.as_str().ends_with(".drv"), "drvPath should end with .drv");
}
Ok(other) => println!("drvPath is {}", other.type_name()),
Err(e) => println!("force drvPath: {e}"),
}
}
#[test]
fn nixos_system_empty_modules_terminates() {
if common::skip_if_offline("m2_6_regression") {
return;
}
let home = std::env::var("HOME").unwrap_or_default();
let nixpkgs_owned = std::path::PathBuf::from(home).join(
".cache/sui/inputs/github-NixOS-nixpkgs-b77b3de/nixpkgs-b77b3de8775677f84492abe84635f87b0e153f0f",
);
let nixpkgs_dir = nixpkgs_owned.as_path();
if !nixpkgs_dir.exists() {
println!("skip: pinned nixpkgs source not in sui input cache");
return;
}
let expr = format!(
"let nixpkgs = builtins.getFlake \"path:{}\"; \
in (nixpkgs.lib.nixosSystem {{ system = \"x86_64-linux\"; modules = []; }}) \
.config.system.name",
nixpkgs_dir.display(),
);
let result = sui_eval::eval(&expr);
let value = result.expect("nixosSystem must evaluate without InfiniteRecursion");
let forced = sui_eval::eval::force_value(&value)
.expect("system.name forces to a concrete value");
match forced {
sui_eval::value::Value::String(s) => {
assert!(!s.as_str().is_empty(), "system.name must not be empty");
println!("nixosSystem returned system.name = {:?}", s.as_str());
}
other => panic!("expected system.name string, got {}", other.type_name()),
}
}
#[test]
fn systems_elaborate_cross_file_intern_parity() {
if common::skip_if_offline("cross_file_intern") {
return;
}
let home = std::env::var("HOME").unwrap_or_default();
let nixpkgs_dir = std::path::PathBuf::from(home).join(
".cache/sui/inputs/github-NixOS-nixpkgs-b77b3de/nixpkgs-b77b3de8775677f84492abe84635f87b0e153f0f",
);
if !nixpkgs_dir.exists() {
println!("skip: pinned nixpkgs source not in sui input cache");
return;
}
let expr = format!(
"((import {}/lib).systems.elaborate \"x86_64-linux\").config",
nixpkgs_dir.display(),
);
let value = sui_eval::eval(&expr)
.expect("elaborate must evaluate (no cross-file intern collision)");
let forced = sui_eval::eval::force_value(&value).expect("config forces");
match forced {
sui_eval::value::Value::String(s) => assert_eq!(
s.as_str(),
"x86_64-unknown-linux-gnu",
"elaborate .config must be byte-identical to cppnix",
),
other => panic!("expected config string, got {}", other.type_name()),
}
}
#[test]
fn flake_input_outpath_is_store_source_not_cache() {
if common::skip_if_offline("marquee_darwin_flake_input_outpath") {
return;
}
let home = std::env::var("HOME").unwrap_or_default();
let darwin_flake = std::path::PathBuf::from(&home).join(
".cache/sui/inputs/github-LnL7-nix-darwin-ebec37af18215214173c98cf6356d0aca24a2585/\
nix-darwin-ebec37af18215214173c98cf6356d0aca24a2585",
);
if !darwin_flake.join("flake.nix").exists() {
println!("skip: pinned nix-darwin flake not in sui input cache");
return;
}
let expr = format!(
"builtins.toString (builtins.getFlake \"path:{}\").inputs.nixpkgs.outPath",
darwin_flake.display(),
);
let value = sui_eval::eval(&expr).expect("getFlake input outPath must evaluate");
let forced = sui_eval::eval::force_value(&value).expect("outPath forces");
match forced {
sui_eval::value::Value::String(s) => {
let p = s.as_str();
println!("flake input nixpkgs.outPath = {p:?}");
assert!(
p.starts_with("/nix/store/") && p.ends_with("-source"),
"flake input outPath must be an in-store `-source` copy, got {p:?}"
);
assert!(
!p.contains(".cache/sui/inputs"),
"flake input outPath must NOT leak the sui fetcher cache path, got {p:?}"
);
}
other => panic!("expected outPath string, got {}", other.type_name()),
}
}