Skip to content

Commit

Permalink
Add holo-dev-server to the dev shell when --holo is passed
Browse files Browse the repository at this point in the history
We add a --holo flag to the example subcommand, it already existed for
the web-app subcommand.
When this flag is passed, we add holo-host/hbs-releases as a flake input
and we add holo-dev-server-bin to the dev shell of the generated nix
flake.
  • Loading branch information
r-vdp committed Mar 20, 2024
1 parent 4dc3d50 commit b31b462
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 9 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
scope: [ hello_world ]
scope:
- hello_world
- holo_integration
steps:
- uses: actions/checkout@v4

Expand Down
52 changes: 50 additions & 2 deletions run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,56 @@ setup_and_build_hello_world() {
cd ..
}

if [[ -n "$SCOPE" && "$SCOPE" == "hello_world" ]]; then
setup_and_build_hello_world
if [[ -n "$SCOPE" ]]; then

case "$SCOPE" in
"hello_world")
setup_and_build_hello_world
;;
"holo_integration")
rm -rf /tmp/holo-flake
cd /tmp

hc-scaffold --template vue web-app holo-flake --setup-nix true
cd holo-flake

nix develop --command bash -c "
set -e
# Check if holo-dev-server is in the path
if command -v holo-dev-server >/dev/null 2>&1; then
echo 'holo-dev-server is available in the PATH while it should not'
exit 1
else
echo 'holo-dev-server is NOT available in the PATH'
fi
"

rm -rf /tmp/holo-flake
cd /tmp

hc-scaffold --template vue web-app holo-flake --setup-nix true --holo
cd holo-flake

nix develop --command bash -c "
set -e
# Check if holo-dev-server is in the path
if command -v holo-dev-server >/dev/null 2>&1; then
echo 'holo-dev-server is available in the PATH'
else
echo 'holo-dev-server is NOT available in the PATH'
exit 1
fi
"

rm -rf /tmp/holo-flake
cd /tmp
;;
*)
echo "Error: SCOPE must be one of 'hello_world', 'holo_integration', but got $SCOPE."
exit 1
;;
esac

exit 0 # Exit early
fi

Expand Down
12 changes: 9 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ pub enum HcScaffoldCommand {
Example {
/// Name of the example to scaffold. One of ['hello-world', 'forum'].
example: Option<Example>,

#[structopt(long = "holo", hidden = true)]
holo_enabled: bool,
},
}

Expand Down Expand Up @@ -674,7 +677,10 @@ Collection "{}" scaffolded!
println!("{}", i);
}
}
HcScaffoldCommand::Example { example } => {
HcScaffoldCommand::Example {
example,
holo_enabled,
} => {
let example = match example {
Some(e) => e,
None => choose_example()?,
Expand All @@ -695,7 +701,7 @@ Collection "{}" scaffolded!
Some(String::from("A simple 'hello world' application.")),
false,
&template_file_tree,
false,
holo_enabled,
)?;

file_tree
Expand All @@ -707,7 +713,7 @@ Collection "{}" scaffolded!
Some(String::from("A simple 'forum' application.")),
false,
&template_file_tree,
false,
holo_enabled,
)?;

// scaffold dna hello_world
Expand Down
19 changes: 17 additions & 2 deletions src/scaffold/app/nix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,21 @@ use crate::error::{ScaffoldError, ScaffoldResult};
use crate::file_tree::*;
use crate::versions::holochain_nix_version;

pub fn flake_nix() -> FileTree {
pub fn flake_nix(holo_enabled: bool) -> FileTree {
let holochain_nix_version = holochain_nix_version();

let holo_inputs = holo_enabled
.then_some(
r#"
hds-releases.url = "github:holo-host/hds-releases";
"#,
)
.unwrap_or("");

let holo_packages = holo_enabled
.then_some("inputs'.hds-releases.packages.holo-dev-server-bin")
.unwrap_or("");

file!(format!(
r#"{{
description = "Template for Holochain app development";
Expand All @@ -23,6 +36,7 @@ pub fn flake_nix() -> FileTree {
nixpkgs.follows = "holochain-flake/nixpkgs";
flake-parts.follows = "holochain-flake/flake-parts";
{holo_inputs}
}};
outputs = inputs:
Expand All @@ -43,6 +57,7 @@ pub fn flake_nix() -> FileTree {
inputsFrom = [ inputs'.holochain-flake.devShells.holonix ];
packages = [
pkgs.nodejs_20
{holo_packages}
# more packages go here
];
}};
Expand Down Expand Up @@ -85,7 +100,7 @@ pub fn setup_nix_developer_environment(dir: &PathBuf) -> ScaffoldResult<()> {
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.current_dir(dir)
.args(["flake", "update"])
.args(["flake", "update", "--accept-flake-config"])
.output()?;

if !output.status.success() {
Expand Down
2 changes: 1 addition & 1 deletion src/scaffold/web_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn web_app_skeleton(
app_file_tree
.dir_content_mut()
.ok_or(ScaffoldError::PathNotFound(PathBuf::new()))?
.insert(OsString::from("flake.nix"), flake_nix());
.insert(OsString::from("flake.nix"), flake_nix(holo_enabled));
}

let mut scaffold_template_result =
Expand Down

0 comments on commit b31b462

Please sign in to comment.