From 436c6e900f59a40dd6224c209417333265e641e7 Mon Sep 17 00:00:00 2001 From: Guillaume Desforges Date: Mon, 7 Mar 2022 17:57:52 +0100 Subject: [PATCH] Explicit error in flake init/new when not in store --- src/nix/flake.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/nix/flake.cc b/src/nix/flake.cc index 144f8f886..6d5ee61be 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -706,9 +706,15 @@ struct CmdFlakeInitCommon : virtual Args, EvalCommand auto [cursor, attrPath] = installable.getCursor(*evalState); - auto templateDir = cursor->getAttr("path")->getString(); + auto templateDirAttr = cursor->getAttr("path"); + auto templateDir = templateDirAttr->getString(); - assert(store->isInStore(templateDir)); + if (!store->isInStore(templateDir)) { + throw TypeError( + std::string("'%s' was not found in the Nix store\n") + + "If you've set '%s' to a string, try using a path instead.", + templateDir, templateDirAttr->getAttrPathStr()); + } std::vector files;