Use "." as the default installable

This makes e.g. "nix build" do something more or less reasonable
(namely, build the default package of the flake in the current
directory).
This commit is contained in:
Eelco Dolstra 2019-04-19 16:07:37 +02:00
parent 4fb594a375
commit cc51e37ad0
3 changed files with 10 additions and 3 deletions

View file

@ -3,7 +3,6 @@
#include "common-args.hh" #include "common-args.hh"
#include "shared.hh" #include "shared.hh"
#include "store-api.hh" #include "store-api.hh"
#include "primops/flake.hh"
using namespace nix; using namespace nix;

View file

@ -108,6 +108,8 @@ struct InstallablesCommand : virtual Args, SourceExprCommand
void prepare() override; void prepare() override;
virtual bool useDefaultInstallables() { return true; }
private: private:
std::vector<std::string> _installables; std::vector<std::string> _installables;
@ -119,14 +121,14 @@ struct InstallableCommand : virtual Args, SourceExprCommand
InstallableCommand() InstallableCommand()
{ {
expectArg("installable", &_installable); expectArg("installable", &_installable, true);
} }
void prepare() override; void prepare() override;
private: private:
std::string _installable; std::string _installable{"."};
}; };
/* A command that operates on zero or more store paths. */ /* A command that operates on zero or more store paths. */
@ -146,6 +148,8 @@ public:
virtual void run(ref<Store> store, Paths storePaths) = 0; virtual void run(ref<Store> store, Paths storePaths) = 0;
void run(ref<Store> store) override; void run(ref<Store> store) override;
bool useDefaultInstallables() override { return !all; }
}; };
/* A command that operates on exactly one store path. */ /* A command that operates on exactly one store path. */

View file

@ -334,6 +334,10 @@ PathSet toDerivations(ref<Store> store,
void InstallablesCommand::prepare() void InstallablesCommand::prepare()
{ {
if (_installables.empty() && !file && useDefaultInstallables())
// FIXME: commands like "nix install" should not have a
// default, probably.
_installables.push_back(".");
installables = parseInstallables(getStore(), _installables); installables = parseInstallables(getStore(), _installables);
} }