-
Notifications
You must be signed in to change notification settings - Fork 36
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 1 commit
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"; | ||
}; | ||
} | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
{ pkgs, lib, name, config, ... }: | ||
let | ||
inherit (lib) types; | ||
in | ||
{ | ||
options = { | ||
enable = lib.mkEnableOption name; | ||
|
||
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 ./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 = | ||
let | ||
browser-sync = lib.getExe pkgs.nodePackages.browser-sync; | ||
cargo-watch = lib.getExe pkgs.cargo-watch; | ||
cargo = lib.getExe pkgs.cargo; | ||
in | ||
{ | ||
"${name}-cargo-doc" = { | ||
command = builtins.toString (pkgs.writeShellScript "cargo-doc" '' | ||
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 = '' | ||
${browser-sync} start --port ${toString config.port} --ss target/doc -s target/doc \ | ||
--startPath /${config.crateName}/ | ||
''; | ||
namespace = name; | ||
depends_on."${name}-cargo-doc".condition = "process_healthy"; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ pkgs, ... }: { | ||
services.cargo-doc-live."cargo-doc-live1" = { | ||
enable = true; | ||
crateName = "simple"; | ||
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. But there's no crate named |
||
}; | ||
|
||
settings.processes.test = | ||
{ | ||
command = pkgs.writeShellApplication { | ||
runtimeInputs = [ pkgs.curl ]; | ||
text = '' | ||
curl http://127.0.0.1:8008/simple | ||
''; | ||
name = "cargo-doc-live-test"; | ||
}; | ||
depends_on."cargo-doc-live1".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?