-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#316 This doesn't do much right now, but renders the Markdown from `om.hack.default.readme`. Spec will change in future iterations. <img width="1058" alt="image" src="https://github.com/user-attachments/assets/7514a389-eecc-418c-b444-5957f4518527">
- Loading branch information
Showing
18 changed files
with
229 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use clap::Parser; | ||
|
||
/// Prepare to hack on a flake project | ||
#[derive(Parser, Debug)] | ||
pub struct HackCommand {} | ||
|
||
impl HackCommand { | ||
pub async fn run(&self) -> anyhow::Result<()> { | ||
omnix_hack::core::hack_on().await?; | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
pub mod ci; | ||
pub mod completion; | ||
pub mod core; | ||
pub mod hack; | ||
pub mod health; | ||
pub mod init; | ||
pub mod show; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[package] | ||
authors = ["Sridhar Ratnakumar <[email protected]>"] | ||
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" | ||
version = "0.1.0" | ||
repository = "https://github.com/juspay/omnix" | ||
description = "Implementation for the `om hack` command" | ||
license = "Apache-2.0" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
anyhow = { workspace = true } | ||
lazy_static = { workspace = true } | ||
nix_rs = { workspace = true } | ||
serde = { workspace = true } | ||
serde_json = { workspace = true } | ||
syntect = { workspace = true } | ||
thiserror = { workspace = true } | ||
tokio = { workspace = true } | ||
tracing = { workspace = true } | ||
omnix-common = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ flake | ||
, pkgs | ||
, lib | ||
, rust-project | ||
, ... | ||
}: | ||
|
||
{ | ||
autoWire = lib.optionals | ||
(lib.elem pkgs.system [ "x86_64-linux" "aarch64-darwin" ]) | ||
[ "doc" "clippy" ]; | ||
crane.args = { | ||
buildInputs = lib.optionals pkgs.stdenv.isDarwin ( | ||
with pkgs.apple_sdk_frameworks; [ | ||
IOKit | ||
] | ||
); | ||
inherit (rust-project.crates."nix_rs".crane.args) | ||
DEFAULT_FLAKE_SCHEMAS | ||
INSPECT_FLAKE | ||
NIX_SYSTEMS | ||
; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use serde::Deserialize; | ||
|
||
use nix_rs::{command::NixCmd, flake::url::FlakeUrl}; | ||
use omnix_common::config::OmConfig; | ||
|
||
use crate::readme::Readme; | ||
|
||
#[derive(Debug, Deserialize, Clone)] | ||
pub struct HackConfig { | ||
pub cache: CacheConfig, | ||
pub readme: Readme, | ||
} | ||
|
||
#[derive(Debug, Deserialize, Clone)] | ||
pub struct CacheConfig { | ||
pub cachix: CachixConfig, | ||
} | ||
|
||
#[derive(Debug, Deserialize, Clone)] | ||
pub struct CachixConfig { | ||
/// If enabled, configure environment to use the cache. | ||
pub enable: bool, | ||
/// Name of the cachix cache (`https://<name>.cachix.org`) | ||
pub name: String, | ||
/// The read-only auth token to use if this is a private cache | ||
/// | ||
/// If provided, will run `cachix authtoken <auth_token>`. | ||
pub auth_token: Option<String>, | ||
} | ||
|
||
impl HackConfig { | ||
pub async fn from_flake(url: &FlakeUrl) -> anyhow::Result<Self> { | ||
let v = OmConfig::<Self>::from_flake_url(NixCmd::get().await, url, &["om.hack"]) | ||
.await? | ||
.config; | ||
v.get("default") | ||
.cloned() | ||
.ok_or_else(|| anyhow::anyhow!("Missing key default for om.hack")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use std::path::Path; | ||
|
||
use nix_rs::flake::url::FlakeUrl; | ||
use omnix_common::markdown::print_markdown; | ||
|
||
use crate::config::HackConfig; | ||
|
||
pub async fn hack_on() -> anyhow::Result<()> { | ||
let here_flake: FlakeUrl = Into::<FlakeUrl>::into(Path::new(".")); | ||
let cfg = HackConfig::from_flake(&here_flake).await?; | ||
|
||
// TODO: cachix check | ||
// TODO: `om health` | ||
|
||
let pwd = std::env::current_dir()?; | ||
eprintln!(); | ||
print_markdown(&pwd, &cfg.readme.get_markdown()).await?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod config; | ||
pub mod core; | ||
pub mod readme; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use serde::Deserialize; | ||
|
||
// TODO(idea): What if we provide `om health` like checkmark for each item. Automatically check if the user is in Nix shell or direnv, and ✅ the title accordingly. If not, nudge them to do it. | ||
const OM_SHELL: &str = r#"## Enter the Nix shell | ||
We recommend that you setup nix-direnv (a convenient template provided at <https://github.com/juspay/nixos-unified-template>), and then run the following in the project terminal to activate the Nix shell: | ||
```sh-session | ||
direnv allow | ||
``` | ||
From this point, anytime you `cd` to this project directory, the Nix shell will be automatically activated. | ||
"#; | ||
|
||
const OM_IDE: &str = r#"## IDE or editor setup | ||
>[!IMPORTANT] ❗Make sure you have setup `direnv` as stated above. | ||
You can now launch your favourite editor or IDE from inside the Nix devshell. For VSCode in particular, consult <https://nixos.asia/en/vscode>. | ||
"#; | ||
|
||
/// The README to display at the end. | ||
/// | ||
/// Placeholder parameters: | ||
/// - `OM_SHELL`: Instructions to enter the Nix shell. | ||
/// - `OM_IDE`: Instructions to setup the IDE. | ||
#[derive(Debug, Deserialize, Clone)] | ||
pub struct Readme(pub String); | ||
|
||
impl Readme { | ||
/// Get the Markdown string, after doing parameter replacements. | ||
pub fn get_markdown(&self) -> String { | ||
self.0 | ||
.replace("OM_SHELL", OM_SHELL) | ||
.replace("OM_IDE", OM_IDE) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Hack | ||
|
||
> [!TODO] | ||
> `om hack` is a work in progress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters