Skip to content
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

fix: parameterize package manager related nixpkgs on scaffolded flakes #373

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/scaffold/app/nix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ use std::process::{Command, Stdio};

use crate::error::{ScaffoldError, ScaffoldResult};
use crate::file_tree::*;
use crate::scaffold::web_app::package_manager::PackageManager;

use super::git::is_inside_work_tree;

pub fn flake_nix(holo_enabled: bool) -> FileTree {
pub fn flake_nix(holo_enabled: bool, package_manager: &PackageManager) -> FileTree {
let holo_inputs = holo_enabled
.then_some(
r#"
Expand Down Expand Up @@ -52,17 +53,17 @@ pub fn flake_nix(holo_enabled: bool) -> FileTree {
rust # For Rust development, with the WASM target included for zome builds
]) ++ (with pkgs; [
nodejs_20
nodePackages.pnpm
yarn-berry
bun
binaryen
{}
{}
]);
}};
}};
}};
}}"#,
holo_inputs, holo_packages
holo_inputs,
package_manager.nixpkg().unwrap_or_default(),
holo_packages
))
}

Expand Down
5 changes: 4 additions & 1 deletion src/scaffold/web_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ pub fn scaffold_web_app(
app_file_tree
.dir_content_mut()
.ok_or(ScaffoldError::PathNotFound(PathBuf::new()))?
.insert("flake.nix".into(), flake_nix(holo_enabled));
.insert(
"flake.nix".into(),
flake_nix(holo_enabled, &package_manager),
);
}

if package_manager == PackageManager::Pnpm {
Expand Down
12 changes: 12 additions & 0 deletions src/scaffold/web_app/package_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ impl PackageManager {
Ok(managers[selection])
}

/// Get's the the package manager's nixpkg that should be used with the generated
/// flake.nix
pub fn nixpkg(&self) -> Option<&str> {
match self {
PackageManager::Bun => Some("bun"),
PackageManager::Pnpm => Some("nodePackages.pnpm"),
PackageManager::Yarn => Some("yarn-berry"),
// npm is already included with nodejs_20
PackageManager::Npm => None,
}
}

/// Checks if the specified lockfile exists in the provided file tree.
pub fn lockfile_exists(app_file_tree: &FileTree, path: &Path) -> bool {
let v = path
Expand Down
3 changes: 0 additions & 3 deletions templates/custom-template/custom-template/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
rust # For Rust development, with the WASM target included for zome builds
]) ++ (with pkgs; [
nodejs_20
nodePackages.pnpm
yarn
bun
binaryen
]);
};
Expand Down