Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename om hack -> om develop #333

Merged
merged 5 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ members = [
"crates/omnix-common",
"crates/omnix-cli",
"crates/omnix-init",
"crates/omnix-hack",
"crates/omnix-develop",
"crates/nix_rs",
"crates/omnix-ci",
"crates/omnix-health",
Expand Down Expand Up @@ -41,7 +41,7 @@ nix_rs = { version = "1.0.0", path = "./crates/nix_rs" }
nonempty = { version = "0.10.0", features = ["serialize"] }
omnix-common = { version = "0.1.0", path = "./crates/omnix-common" }
omnix-init = { version = "0.1.0", path = "./crates/omnix-init" }
omnix-hack = { version = "0.1.0", path = "./crates/omnix-hack" }
omnix-develop = { version = "0.1.0", path = "./crates/omnix-develop" }
os_info = "3.7.0"
reqwest = { version = "0.11", features = ["blocking", "json"] }
regex = "1.9.3"
Expand Down
4 changes: 2 additions & 2 deletions bacon.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ command = [
need_stdout = true
allow_warnings = true

[jobs.hack]
[jobs.develop]
command = [
"cargo",
"run",
"--color",
"always",
"--",
"hack",
"develop",
".",
]
need_stdout = true
Expand Down
4 changes: 2 additions & 2 deletions crates/nix_rs/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ static NIXCMD: OnceCell<NixCmd> = OnceCell::const_new();
/// rest of the instrumentation parameters.
#[instrument(name = "command")]
pub fn trace_cmd(cmd: &tokio::process::Command) {
trace_cmd_with("", cmd);
trace_cmd_with("❄️ ", cmd);
}

/// Like [trace_cmd] but with a custom icon
#[instrument(name = "command")]
pub fn trace_cmd_with(icon: &str, cmd: &tokio::process::Command) {
use colored::Colorize;
tracing::info!("{} {}️", icon, to_cli(cmd).dimmed());
tracing::info!("{}", format!("{} {}️", icon, to_cli(cmd)).dimmed());
}

impl NixCmd {
Expand Down
2 changes: 1 addition & 1 deletion crates/omnix-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ omnix-health = { workspace = true }
nix_rs = { workspace = true }
omnix-common = { workspace = true }
omnix-init = { workspace = true }
omnix-hack = { workspace = true }
omnix-develop = { workspace = true }
tabled = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
Expand Down
5 changes: 3 additions & 2 deletions crates/omnix-cli/src/command/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ pub enum Command {

Init(super::init::InitCommand),

Hack(super::hack::HackCommand),
#[clap(alias = "hack")]
Develop(super::develop::DevelopCommand),

CI(super::ci::CICommand),

Expand All @@ -26,7 +27,7 @@ impl Command {
match self {
Command::Show(cmd) => cmd.run().await,
Command::Init(cmd) => cmd.run().await,
Command::Hack(cmd) => cmd.run().await,
Command::Develop(cmd) => cmd.run().await,
Command::CI(cmd) => cmd.run(verbosity).await,
Command::Health(cmd) => cmd.run().await,
Command::Completion(cmd) => cmd.run(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std::path::PathBuf;

use clap::Parser;

/// Prepare to hack on a flake project
/// Prepare to develop on a flake project
#[derive(Parser, Debug)]
pub struct HackCommand {
pub struct DevelopCommand {
/// Directory of the project
#[arg(name = "DIR", default_value = ".")]
dir: PathBuf,
Expand All @@ -24,13 +24,17 @@ enum Stage {
PostShell,
}

impl HackCommand {
impl DevelopCommand {
pub async fn run(&self) -> anyhow::Result<()> {
let prj = omnix_hack::core::Project::new(&self.dir).await?;
tracing::info!(
"⌨️ Preparing to develop project at {:}",
self.dir.display()
);
let prj = omnix_develop::core::Project::new(&self.dir).await?;
match self.stage {
Some(Stage::PreShell) => omnix_hack::core::hack_on_pre_shell(&prj).await?,
Some(Stage::PostShell) => omnix_hack::core::hack_on_post_shell(&prj).await?,
None => omnix_hack::core::hack_on(&prj).await?,
Some(Stage::PreShell) => omnix_develop::core::develop_on_pre_shell(&prj).await?,
Some(Stage::PostShell) => omnix_develop::core::develop_on_post_shell(&prj).await?,
None => omnix_develop::core::develop_on(&prj).await?,
}
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion crates/omnix-cli/src/command/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod ci;
pub mod completion;
pub mod core;
pub mod hack;
pub mod develop;
pub mod health;
pub mod init;
pub mod show;
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
authors = ["Sridhar Ratnakumar <srid@srid.ca>"]
edition = "2021"
# If you change the name here, you must also do it in flake.nix (and run `cargo generate-lockfile` afterwards)
name = "omnix-hack"
name = "omnix-develop"
version = "0.1.0"
repository = "https://github.com/juspay/omnix"
description = "Implementation for the `om hack` command"
description = "Implementation for the `om develop` command"
license = "Apache-2.0"

[lib]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use omnix_common::config::OmConfig;
use crate::readme::Readme;

#[derive(Debug, Deserialize, Clone, Default)]
pub struct HackConfig {
pub struct DevelopConfig {
pub readme: Readme,
}

Expand All @@ -16,9 +16,9 @@ pub struct CacheConfig {
pub url: String,
}

impl HackConfig {
impl DevelopConfig {
pub async fn from_flake(url: &FlakeUrl) -> anyhow::Result<Self> {
let v = OmConfig::<Self>::from_flake_url(NixCmd::get().await, url, &["om.hack"])
let v = OmConfig::<Self>::from_flake_url(NixCmd::get().await, url, &["om.develop"])
.await?
.config;
let config = v.get("default").cloned().unwrap_or_default();
Expand Down
28 changes: 17 additions & 11 deletions crates/omnix-hack/src/core.rs → crates/omnix-develop/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,40 @@ use nix_rs::{flake::url::FlakeUrl, info::NixInfo};
use omnix_common::markdown::print_markdown;
use omnix_health::{check::caches::CachixCache, traits::Checkable, NixHealth};

use crate::config::HackConfig;
use crate::config::DevelopConfig;

/// A project that an be hacked on locally.
/// A project that an be developed on locally.
pub struct Project {
/// The directory of the project.
pub dir: PathBuf,
/// [FlakeUrl] corresponding to the project.
pub flake: FlakeUrl,
/// The hack configuration
pub cfg: HackConfig,
/// The develop configuration
pub cfg: DevelopConfig,
}

impl Project {
pub async fn new(dir: &Path) -> anyhow::Result<Self> {
let dir = dir.canonicalize()?;
let flake: FlakeUrl = Into::<FlakeUrl>::into(dir.as_ref());
let cfg = HackConfig::from_flake(&flake).await?;
let cfg = DevelopConfig::from_flake(&flake).await?;
Ok(Self { dir, flake, cfg })
}
}

pub async fn hack_on(prj: &Project) -> anyhow::Result<()> {
hack_on_pre_shell(prj).await?;
hack_on_post_shell(prj).await?;
pub async fn develop_on(prj: &Project) -> anyhow::Result<()> {
develop_on_pre_shell(prj).await?;
develop_on_post_shell(prj).await?;

tracing::warn!("");
tracing::warn!("🚧 !!!!");
tracing::warn!("🚧 Not invoking Nix devShell (not supported yet). Please use `direnv`!");
tracing::warn!("🚧 !!!!");
Ok(())
}

pub async fn hack_on_pre_shell(prj: &Project) -> anyhow::Result<()> {
pub async fn develop_on_pre_shell(prj: &Project) -> anyhow::Result<()> {
// Run relevant `om health` checks
tracing::info!("om hack: Running pre-shell checks");
let health = NixHealth::from_flake(&prj.flake).await?;
let nix_info = NixInfo::get()
.await
Expand Down Expand Up @@ -74,10 +78,12 @@ pub async fn hack_on_pre_shell(prj: &Project) -> anyhow::Result<()> {
}
}

tracing::info!("✅ Nix environment is healthy.");

Ok(())
}

pub async fn hack_on_post_shell(prj: &Project) -> anyhow::Result<()> {
pub async fn develop_on_post_shell(prj: &Project) -> anyhow::Result<()> {
eprintln!();
print_markdown(&prj.dir, prj.cfg.readme.get_markdown()).await?;
Ok(())
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use serde::Deserialize;

const DEFAULT: &str = r#"🍾 Welcome to the project

*(Want to show custom instructions here? Add them to the `om.hack.default.readme` field in your `flake.nix` file)*
*(Want to show custom instructions here? Add them to the `om.develop.default.readme` field in your `flake.nix` file)*
"#;

/// The README to display at the end.
Expand Down
2 changes: 1 addition & 1 deletion doc/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- [CLI](om/index.md)
- [Show](om/show.md)
- [Health](om/health.md)
- [Hack](om/hack.md)
- [Develop](om/develop.md)
- [CI](om/ci.md)
- [Init](om/init.md)

Expand Down
2 changes: 1 addition & 1 deletion doc/src/history.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### Enhancements

- `om hack`: New command
- `om develop`: New command
- `om init`
- Initial working version of `om init` command
- `om health`
Expand Down
7 changes: 7 additions & 0 deletions doc/src/om/develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Develop

> [!TODO]
> `om develop` is a work in progress, but checkout [Emanote's `.envrc`](https://github.com/srid/emanote/blob/master/.envrc) to see what is available so far.

- Tight `direnv` integration
- Health check; `cachix use`
7 changes: 0 additions & 7 deletions doc/src/om/hack.md

This file was deleted.

2 changes: 1 addition & 1 deletion nix/modules/flake-parts/om.nix
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
caches.required = [ "https://om.cachix.org" ];
direnv.required = true;
};
hack.default = {
develop.default = {
readme = ''
🍾 Welcome to the **omnix** project

Expand Down