Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into e2e-playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
srid committed Sep 11, 2023
2 parents a452d36 + fa96260 commit f2aae2c
Show file tree
Hide file tree
Showing 19 changed files with 243 additions and 56 deletions.
72 changes: 66 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ default-members = [".", "crates/*"]
[workspace.package]
edition = "2021"
license = "AGPL-3.0-only"
repository = "https://github.com/juspay/nix-browser"

[workspace.dependencies]
cfg-if = "1"
human-panic = "1.1.5"
leptos = { version = "0.4", features = ["serde", "nightly"] }
leptos_meta = { version = "0.4", features = ["nightly"] }
leptos_router = { version = "0.4", features = ["nightly"] }
Expand All @@ -15,7 +17,7 @@ tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tracing-subscriber-wasm = "0.1"
wasm-bindgen = "=0.2.87" # The version here must match the pinned stuff in Nix flakes.
nix_rs = { path = "./crates/nix_rs" }
nix_rs = { version = "0.1", path = "./crates/nix_rs" }
nix_health = { path = "./crates/nix_health" }
leptos_extra = { path = "./crates/leptos_extra" }
thiserror = "1.0"
Expand All @@ -30,6 +32,9 @@ name = "nix-browser"
version = "0.1.0"
homepage = "https://github.com/juspay/nix-browser"

[package.metadata.docs.rs]
all-features = true

[lib]
crate-type = ["cdylib", "rlib"]

Expand All @@ -43,7 +48,7 @@ clap = { version = "4.3", features = ["derive", "env"] }
console_error_panic_hook = "0.1"
console_log = { version = "1" }
http = { version = "0.2", optional = true }
human-panic = "1.1.5"
human-panic.workspace = true
hyper = { version = "0.14", features = ["server"], optional = true }
leptos.workspace = true
leptos_axum = { version = "0.4", optional = true }
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ We publish the following crates from this repo:
| Crate Link | Description |
|------------|-------------|
| https://crates.io/crates/nix_rs | Rust interface to the Nix command line |
| https://crates.io/crates/nix_health | Nix health check library and executable |
18 changes: 13 additions & 5 deletions crates/nix_health/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
[package]
edition = "2021"
edition.workspace = true
name = "nix_health"
version = "0.1.0"
license.workspace = true
repository.workspace = true
description = "Health check for the user's Nix environment"

[lib]
crate-type = ["cdylib", "rlib"]

[[bin]]
name = "nix-health"
path = "src/main.rs"
required-features = ["ssr"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Expand All @@ -16,11 +24,11 @@ serde.workspace = true
serde_json.workspace = true
serde_with.workspace = true
tokio = { version = "1.29", features = ["full"], optional = true }
tracing.workspace = true
tracing-subscriber.workspace = true
tracing-subscriber-wasm.workspace = true
url = { version = "2.4", features = ["serde"] }
nix_rs.workspace = true
human-panic.workspace = true
anyhow = { version = "1.0.75", optional = true }
colored = { version = "2.0", optional = true }

[features]
ssr = ["dep:tokio", "nix_rs/ssr"]
ssr = ["dep:tokio", "dep:anyhow", "dep:colored", "nix_rs/ssr"]
1 change: 1 addition & 0 deletions crates/nix_health/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Next-gen version of <https://github.com/srid/nix-health> in progress.
30 changes: 25 additions & 5 deletions crates/nix_health/src/check/caches.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Display;

use nix_rs::{config::ConfigVal, info};
use serde::{Deserialize, Serialize};
use url::Url;
Expand All @@ -7,7 +9,7 @@ use crate::{
traits::Check,
};

/// Check that [crate::config::NixConfig::substituters] is set to a good value.
/// Check that [nix_rs::config::NixConfig::substituters] is set to a good value.
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Caches(pub ConfigVal<Vec<Url>>);

Expand All @@ -20,14 +22,17 @@ impl Check for Caches {
}
fn report(&self) -> Report<WithDetails> {
let val = &self.0.value;
// TODO: Hardcoding this to test failed reports
// TODO: Make this customizable in a flake
let required_cache = Url::parse("https://nix-community.cachix.org").unwrap();
if val.contains(&Url::parse("https://cache.nixos.org").unwrap()) {
// TODO: Hardcoding this to test failed reports
if val.contains(&Url::parse("https://nammayatri.cachix.org").unwrap()) {
if val.contains(&required_cache) {
Report::Green
} else {
Report::Red(WithDetails {
msg: "You are missing the nammayatri cache".into(),
suggestion: "Run 'nix run nixpkgs#cachix use nammayatri".into(),
msg: format!("You are missing a required cache: {}", required_cache),
// TODO: Suggestion should be smart. Use 'cachix use' if a cachix cache.
suggestion: "Add substituters in /etc/nix/nix.conf or use 'cachix use'".into(),
})
}
} else {
Expand All @@ -38,3 +43,18 @@ impl Check for Caches {
}
}
}

impl Display for Caches {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"substituters = {}",
self.0
.value
.iter()
.map(|url| url.to_string())
.collect::<Vec<String>>()
.join(" ")
)
}
}
10 changes: 9 additions & 1 deletion crates/nix_health/src/check/flake_enabled.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Display;

use nix_rs::{config::ConfigVal, info};
use serde::{Deserialize, Serialize};

Expand All @@ -6,7 +8,7 @@ use crate::{
traits::Check,
};

/// Check that [crate::config::NixConfig::experimental_features] is set to a good value.
/// Check that [nix_rs::config::NixConfig::experimental_features] is set to a good value.
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct FlakeEnabled(pub ConfigVal<Vec<String>>);

Expand All @@ -29,3 +31,9 @@ impl Check for FlakeEnabled {
}
}
}

impl Display for FlakeEnabled {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "experimental-features = {}", self.0.value.join(" "))
}
}
10 changes: 9 additions & 1 deletion crates/nix_health/src/check/max_jobs.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Display;

use nix_rs::{config::ConfigVal, info};
use serde::{Deserialize, Serialize};

Expand All @@ -6,7 +8,7 @@ use crate::{
traits::Check,
};

/// Check that [crate::config::NixConfig::max_jobs] is set to a good value.
/// Check that [nix_rs::config::NixConfig::max_jobs] is set to a good value.
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct MaxJobs(pub ConfigVal<i32>);

Expand All @@ -28,3 +30,9 @@ impl Check for MaxJobs {
}
}
}

impl Display for MaxJobs {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "max-jobs = {}", self.0.value)
}
}
10 changes: 9 additions & 1 deletion crates/nix_health/src/check/min_nix_version.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Display;

use nix_rs::{info, version::NixVersion};
use serde::{Deserialize, Serialize};

Expand All @@ -6,7 +8,7 @@ use crate::{
traits::Check,
};

/// Check that [crate::version::NixVersion] is set to a good value.
/// Check that [nix_rs::version::NixVersion] is set to a good value.
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct MinNixVersion(pub NixVersion);

Expand All @@ -33,3 +35,9 @@ impl Check for MinNixVersion {
}
}
}

impl Display for MinNixVersion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "nix version = {}", self.0)
}
}
8 changes: 8 additions & 0 deletions crates/nix_health/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ pub mod check;
pub mod report;
pub mod traits;

use std::fmt::Display;

use nix_rs::info;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -66,3 +68,9 @@ impl Check for NixHealth {
}
}
}

impl Display for NixHealth {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "")
}
}
Loading

0 comments on commit f2aae2c

Please sign in to comment.