From c2f303fd8be05039958b5fefcd0ea38e362cf04b Mon Sep 17 00:00:00 2001 From: oxalica Date: Fri, 5 May 2023 10:45:13 +0800 Subject: [PATCH] Add tests for option evaluation of nixpkgs 22.11 --- Cargo.lock | 28 +++++++- crates/nix-interop/Cargo.toml | 2 +- crates/nix-interop/src/nixos_options.rs | 66 +++++++++++++------ .../nix-interop/tests/nixpkgs_revs/flake.lock | 44 +++++++++++++ .../nix-interop/tests/nixpkgs_revs/flake.nix | 9 +++ 5 files changed, 125 insertions(+), 24 deletions(-) create mode 100644 crates/nix-interop/tests/nixpkgs_revs/flake.lock create mode 100644 crates/nix-interop/tests/nixpkgs_revs/flake.nix diff --git a/Cargo.lock b/Cargo.lock index 55315fd..700144d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -541,7 +541,17 @@ checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" dependencies = [ "instant", "lock_api", - "parking_lot_core", + "parking_lot_core 0.8.6", +] + +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core 0.9.7", ] [[package]] @@ -558,6 +568,19 @@ dependencies = [ "winapi", ] +[[package]] +name = "parking_lot_core" +version = "0.9.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-sys 0.45.0", +] + [[package]] name = "percent-encoding" version = "2.2.0" @@ -746,7 +769,7 @@ dependencies = [ "lock_api", "log", "oorandom", - "parking_lot", + "parking_lot 0.11.2", "rustc-hash", "salsa-macros", "smallvec", @@ -972,6 +995,7 @@ dependencies = [ "bytes", "libc", "mio", + "parking_lot 0.12.1", "pin-project-lite", "signal-hook-registry", "socket2", diff --git a/crates/nix-interop/Cargo.toml b/crates/nix-interop/Cargo.toml index 385d027..65103fa 100644 --- a/crates/nix-interop/Cargo.toml +++ b/crates/nix-interop/Cargo.toml @@ -14,4 +14,4 @@ syntax = { path = "../syntax" } tokio = { version = "1.27.0", features = ["io-util", "macros", "process", "sync"] } [dev-dependencies] -tokio = { version = "1.27.0", features = ["macros", "rt", "sync"] } +tokio = { version = "1.27.0", features = ["macros", "parking_lot", "rt", "sync"] } # parking_lot is required for `OnceCell::const_new`. diff --git a/crates/nix-interop/src/nixos_options.rs b/crates/nix-interop/src/nixos_options.rs index a375df5..d4f474f 100644 --- a/crates/nix-interop/src/nixos_options.rs +++ b/crates/nix-interop/src/nixos_options.rs @@ -157,30 +157,42 @@ pub enum Ty { #[cfg(test)] mod tests { + use tokio::sync::OnceCell; + + use crate::FlakeUrl; + use super::*; - #[tokio::test] - #[ignore = "requires using 'nix' and ''"] - async fn nixos_options() { - let output = Command::new("nix") - .kill_on_drop(true) - .args([ - "eval", - "--experimental-features", - "nix-command", - "--impure", - "--expr", - "", - ]) - .stdin(Stdio::null()) - .stdout(Stdio::piped()) - .stderr(Stdio::inherit()) - .output() + async fn check_nixpkgs(name: &str) { + static LOCKED: OnceCell = OnceCell::const_new(); + + let nixpkgs_path = LOCKED + .get_or_init(|| async { + let output = Command::new("nix") + .kill_on_drop(true) + .args([ + "flake", + "archive", + "--experimental-features", + "nix-command flakes", + "--json", + ]) + .arg(FlakeUrl::new_path("./tests/nixpkgs_revs")) + .stdin(Stdio::null()) + // Configures stdout/stderr automatically. + .output() + .await + .unwrap(); + serde_json::from_slice::(&output.stdout).unwrap() + }) .await - .unwrap(); - assert!(output.status.success()); - let nixpkgs_path = String::from_utf8(output.stdout).unwrap(); - let opts = eval_all_options("nix".as_ref(), nixpkgs_path.trim().as_ref()) + .pointer(&format!("/inputs/{name}/path")) + .unwrap() + .as_str() + .unwrap() + .to_owned(); + + let opts = eval_all_options("nix".as_ref(), nixpkgs_path.as_ref()) .await .unwrap(); @@ -193,4 +205,16 @@ mod tests { Some(Doc::Markdown { text }) if text.starts_with("Whether to enable Nix.") )); } + + #[tokio::test] + #[ignore = "requires using 'nix' and network"] + async fn nixos_unstable() { + check_nixpkgs("nixos-unstable").await; + } + + #[tokio::test] + #[ignore = "requires using 'nix' and ''"] + async fn nixos_22_11() { + check_nixpkgs("nixos-22-11").await; + } } diff --git a/crates/nix-interop/tests/nixpkgs_revs/flake.lock b/crates/nix-interop/tests/nixpkgs_revs/flake.lock new file mode 100644 index 0000000..ce7323a --- /dev/null +++ b/crates/nix-interop/tests/nixpkgs_revs/flake.lock @@ -0,0 +1,44 @@ +{ + "nodes": { + "nixos-22-11": { + "locked": { + "lastModified": 1683207485, + "narHash": "sha256-gs+PHt/y/XQB7S8+YyBLAM8LjgYpPZUVFQBwpFSmJro=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "cc45a3f8c98e1c33ca996e3504adefbf660a72d1", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-22.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixos-unstable": { + "locked": { + "lastModified": 1683014792, + "narHash": "sha256-6Va9iVtmmsw4raBc3QKvQT2KT/NGRWlvUlJj46zN8B8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "1a411f23ba299db155a5b45d5e145b85a7aafc42", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixos-22-11": "nixos-22-11", + "nixos-unstable": "nixos-unstable" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/crates/nix-interop/tests/nixpkgs_revs/flake.nix b/crates/nix-interop/tests/nixpkgs_revs/flake.nix new file mode 100644 index 0000000..da60bdb --- /dev/null +++ b/crates/nix-interop/tests/nixpkgs_revs/flake.nix @@ -0,0 +1,9 @@ +{ + # Just for tests. No need to be up-to-date. + inputs = { + nixos-unstable.url = "github:NixOS/nixpkgs/nixos-unstable"; + nixos-22-11.url = "github:NixOS/nixpkgs/nixos-22.11"; + }; + + outputs = inputs: { }; +}