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.
When this flag is passed, we add holo-nixpkgs as a flake input and we
add holo-dev-server to the dev shell's packages.
  • Loading branch information
r-vdp committed Jan 15, 2024
1 parent dc10337 commit 87e3f64
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 5 deletions.
37 changes: 37 additions & 0 deletions run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,40 @@ set -e
npm i
npm t
"

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

hc-scaffold web-app holo-flake --template vue
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 shouldn\'t'
exit 1
else
echo 'holo-dev-server is NOT available in the PATH'
fi
"

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

hc-scaffold web-app holo-flake --template vue --holo
cd holo-flake

nix develop --accept-flake-config --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
13 changes: 10 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ pub enum HcScaffold {
/// The template to scaffold the example for
/// Must be an option from the built-in templates: "vanilla", "vue", "lit", "svelte"
template: Option<String>,

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

Expand Down Expand Up @@ -702,7 +705,11 @@ Collection "{}" scaffolded!
println!("{}", i);
}
}
HcScaffold::Example { example, template } => {
HcScaffold::Example {
example,
template,
holo_enabled,
} => {
let example = match example {
Some(e) => e,
None => choose_example()?,
Expand Down Expand Up @@ -736,7 +743,7 @@ Collection "{}" scaffolded!
&template_file_tree,
template_name.clone(),
false,
false,
holo_enabled,
)?;

file_tree
Expand All @@ -750,7 +757,7 @@ Collection "{}" scaffolded!
&template_file_tree,
template_name.clone(),
false,
false,
holo_enabled,
)?;

// scaffold dna hello_world
Expand Down
41 changes: 40 additions & 1 deletion src/scaffold/app/nix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,49 @@ 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_nix_config = holo_enabled
.then_some(
r#"
nixConfig = {
extra-substituters = [
"https://cache.holo.host"
];
extra-trusted-public-keys = [
"cache.holo.host-1:lNXIXtJgS9Iuw4Cu6X0HINLu9sTfcjEntnrgwMQIMcE="
"cache.holo.host-2:ZJCkX3AUYZ8soxTLfTb60g+F3MkWD7hkH9y8CgqwhDQ="
];
};"#,
)
.unwrap_or("");

let holo_inputs = holo_enabled
.then_some(
r#"
holo-nixpkgs = {
# Take the latest version from the Holo-Host develop branch
url = "https://hydra.holo.host/job/holo-nixpkgs/develop/holo-nixpkgs/latest/download";
inputs = {
versions.follows = "holochain-flake/versions";
holochain.follows = "holochain-flake";
flake-compat.follows = "holochain-flake/flake-compat";
};
};"#,
)
.unwrap_or("");

let holo_packages = holo_enabled
.then_some("inputs'.holo-nixpkgs.legacyPackages.holo-dev-server")
.unwrap_or("");

file!(format!(
r#"{{
description = "Template for Holochain app development";
{holo_nix_config}
inputs = {{
versions.url = "github:holochain/holochain?dir=versions/{holochain_nix_version}";
Expand All @@ -23,6 +60,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 +81,7 @@ pub fn flake_nix() -> FileTree {
inputsFrom = [ inputs'.holochain-flake.devShells.holonix ];
packages = [
pkgs.nodejs-18_x
{holo_packages}
# more packages go here
];
}};
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 @@ -41,7 +41,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));
}
if scaffold_template {
app_file_tree
Expand Down

0 comments on commit 87e3f64

Please sign in to comment.