-
Notifications
You must be signed in to change notification settings - Fork 31
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
feat: Add cargo-doc-live #246
base: main
Are you sure you want to change the base?
Changes from 4 commits
7e2eb09
109a6db
3695662
7a465f8
7877ddc
6de6f59
3745923
3fa26c0
8a003fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# cargo-doc-live | ||
|
||
[cargo-doc-live] is live server version of `cargo doc`. | ||
|
||
{#start} | ||
|
||
## Getting started | ||
|
||
```nix | ||
# In `perSystem.process-compose.<name>` | ||
{ | ||
services.cargo-doc-live."cargo-doc-live1".enable = true; | ||
} | ||
``` | ||
|
||
{#port} | ||
|
||
### The port for `cargo doc` | ||
|
||
```nix | ||
{ | ||
services.cargo-doc-live."cargo-doc-live1" = { | ||
enable = true; | ||
port = 8080; | ||
}; | ||
} | ||
``` | ||
|
||
{#crateName} | ||
|
||
### The crate to use when opening docs in browser | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know our docs elsewhere are more of skeleton, but we should get into the practice of fleshing out when writing new docs. Can you add some paragraphs to all these sections? |
||
|
||
```nix | ||
{ | ||
services.cargo-doc-live."cargo-doc-live1" = { | ||
enable = true; | ||
crateName = "chrono"; | ||
}; | ||
} | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[package] | ||
name = "test" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,44 @@ | ||||||
{ | ||||||
inputs = { | ||||||
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; | ||||||
flake-parts.url = "github:hercules-ci/flake-parts"; | ||||||
systems.url = "github:nix-systems/default"; | ||||||
process-compose-flake.url = "github:Platonic-Systems/process-compose-flake"; | ||||||
services-flake.url = "github:juspay/services-flake"; | ||||||
}; | ||||||
outputs = inputs: | ||||||
inputs.flake-parts.lib.mkFlake { inherit inputs; } { | ||||||
systems = import inputs.systems; | ||||||
imports = [ | ||||||
inputs.process-compose-flake.flakeModule | ||||||
]; | ||||||
perSystem = { self', pkgs, lib, ... }: { | ||||||
# `process-compose.foo` will add a flake package output called "foo". | ||||||
# Therefore, this will add a default package that you can build using | ||||||
# `nix build` and run using `nix run`. | ||||||
process-compose."default" = { ... }: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
(The default package is usually the Rust package itself) |
||||||
{ | ||||||
imports = [ | ||||||
inputs.services-flake.processComposeModules.default | ||||||
]; | ||||||
|
||||||
services.cargo-doc-live."cargo-doc-live1" = { | ||||||
src = inputs.self; | ||||||
enable = true; | ||||||
port = 8009; | ||||||
}; | ||||||
|
||||||
settings.processes.test = { | ||||||
command = pkgs.writeShellApplication { | ||||||
name = "cargo-doc-live-test"; | ||||||
runtimeInputs = [ pkgs.curl ]; | ||||||
text = '' | ||||||
curl http://127.0.0.1:8009/test | ||||||
''; | ||||||
}; | ||||||
depends_on."cargo-doc-live1".condition = "process_healthy"; | ||||||
}; | ||||||
}; | ||||||
}; | ||||||
}; | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
println!("Hello, world!"); | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,83 @@ | ||||||
{ pkgs, lib, name, config, ... }: | ||||||
let | ||||||
inherit (lib) types; | ||||||
in | ||||||
{ | ||||||
options = { | ||||||
enable = lib.mkEnableOption name; | ||||||
|
||||||
src = lib.mkOption { | ||||||
type = types.path; | ||||||
description = "The src of the cargo"; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}; | ||||||
|
||||||
port = lib.mkOption { | ||||||
type = types.port; | ||||||
description = "The port for 'cargo doc'"; | ||||||
default = 8008; | ||||||
}; | ||||||
|
||||||
crateName = lib.mkOption { | ||||||
type = types.str; | ||||||
description = "The crate to use when opening docs in browser"; | ||||||
default = builtins.replaceStrings [ "-" ] [ "_" ] | ||||||
((lib.trivial.importTOML "${config.src}/Cargo.toml").package.name); | ||||||
defaultText = "The crate name is derived from the Cargo.toml file"; | ||||||
}; | ||||||
|
||||||
outputs.settings = lib.mkOption { | ||||||
type = types.deferredModule; | ||||||
internal = true; | ||||||
readOnly = true; | ||||||
default = { | ||||||
processes = | ||||||
{ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||||||
"${name}-cargo-doc" = { | ||||||
command = pkgs.writeShellApplication { | ||||||
name = "cargo-doc"; | ||||||
runtimeInputs = with pkgs; [ cargo cargo-watch nodePackages.browser-sync ]; | ||||||
text = | ||||||
let | ||||||
browser-sync = lib.getExe pkgs.nodePackages.browser-sync; | ||||||
cargo-watch = lib.getExe pkgs.cargo-watch; | ||||||
cargo = lib.getExe pkgs.cargo; | ||||||
in | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since these are in |
||||||
'' | ||||||
run-cargo-doc() { | ||||||
${cargo} doc --document-private-items --all-features | ||||||
${browser-sync} reload --port ${toString config.port} # Trigger reload in browser | ||||||
}; export -f run-cargo-doc | ||||||
${cargo-watch} watch -s run-cargo-doc | ||||||
''; | ||||||
}; | ||||||
readiness_probe = { | ||||||
period_seconds = 1; | ||||||
failure_threshold = 100000; # 'cargo doc' can take quite a while. | ||||||
exec.command = '' | ||||||
# Wait for the first 'cargo doc' to have completed. | ||||||
# We'll use this state to block browser-sync from starting | ||||||
# and opening the URL in the browser. | ||||||
ls target/doc/${config.crateName}/index.html | ||||||
''; | ||||||
}; | ||||||
namespace = name; | ||||||
availability.restart = "on_failure"; | ||||||
}; | ||||||
"${name}-browser-sync" = { | ||||||
command = pkgs.writeShellApplication { | ||||||
name = "browser-sync"; | ||||||
runtimeInputs = with pkgs; [ nodePackages.browser-sync ]; | ||||||
text = | ||||||
'' | ||||||
${lib.getExe pkgs.nodePackages.browser-sync} start --port ${toString config.port} --ss target/doc -s target/doc \ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
--startPath /${config.crateName}/ | ||||||
''; | ||||||
}; | ||||||
namespace = name; | ||||||
depends_on."${name}-cargo-doc".condition = "process_healthy"; | ||||||
}; | ||||||
}; | ||||||
}; | ||||||
}; | ||||||
}; | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,5 +22,6 @@ in | |
./tempo.nix | ||
./weaviate.nix | ||
./searxng.nix | ||
./cargo-doc-live.nix | ||
]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use the 1st paragraph and video from https://github.com/srid/cargo-doc-live in here?