Open garbas opened 3 years ago
diff --git a/src/nix/flake.cc b/src/nix/flake.cc
index 64fcfc000..80ae6d901 100644
--- a/src/nix/flake.cc
+++ b/src/nix/flake.cc
@@ -638,6 +638,12 @@ struct CmdFlakeInitCommon : virtual Args, EvalCommand
auto [templateFlakeRef, templateName] = parseFlakeRefWithFragment(templateUrl, absPath("."));
+ if (templateName == "") {
+ notice("No template provided. Use `--template` or `-t` to select a template.");
+ notice("For available templates visit: https://github.com/NixOS/templates");
+ return;
+ }
+
auto installable = InstallableFlake(nullptr,
evalState, std::move(templateFlakeRef),
Strings{templateName == "" ? "defaultTemplate" : templateName},
Currently when creating a project (using
nix flake init
ornix flake new
) a simple and minimal default project is created. It contains onlyflake.nix
. Current situation is probably suitable mostly for very advanced users.I would suggest that we should not select any default template. Nix is used in many different and assuming the defaults in this space would be a mistake.
Rather then assuming let us ask the user which template to use. Here is how this could look like:
Nix could also detect if
fzf
binary is present on the system and provide a filter.We must know that creating a project is not a common task (like
nix build
ornix develop
). Also this command is going to primarily benefit new comers and users learning Nix. While it might be useful for advanced users, they should not be a target audience.