2016-02-09 20:28:29 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "args.hh"
|
2017-10-24 10:45:11 +00:00
|
|
|
|
#include "common-eval-args.hh"
|
2016-02-09 20:28:29 +00:00
|
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
2018-01-31 15:14:47 +00:00
|
|
|
|
extern std::string programPath;
|
|
|
|
|
|
2017-04-25 10:06:32 +00:00
|
|
|
|
struct Value;
|
2017-12-11 17:51:55 +00:00
|
|
|
|
class Bindings;
|
2017-04-25 10:06:32 +00:00
|
|
|
|
class EvalState;
|
|
|
|
|
|
2016-02-09 20:28:29 +00:00
|
|
|
|
/* A command is an argument parser that can be executed by calling its
|
|
|
|
|
run() method. */
|
|
|
|
|
struct Command : virtual Args
|
|
|
|
|
{
|
|
|
|
|
virtual std::string name() = 0;
|
|
|
|
|
virtual void prepare() { };
|
|
|
|
|
virtual void run() = 0;
|
2016-04-21 12:58:32 +00:00
|
|
|
|
|
|
|
|
|
struct Example
|
|
|
|
|
{
|
|
|
|
|
std::string description;
|
|
|
|
|
std::string command;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef std::list<Example> Examples;
|
|
|
|
|
|
|
|
|
|
virtual Examples examples() { return Examples(); }
|
|
|
|
|
|
|
|
|
|
void printHelp(const string & programName, std::ostream & out) override;
|
2016-02-09 20:28:29 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Store;
|
|
|
|
|
|
|
|
|
|
/* A command that require a Nix store. */
|
|
|
|
|
struct StoreCommand : virtual Command
|
|
|
|
|
{
|
2016-03-21 17:03:36 +00:00
|
|
|
|
StoreCommand();
|
2016-02-09 20:28:29 +00:00
|
|
|
|
void run() override;
|
2017-04-25 09:20:37 +00:00
|
|
|
|
ref<Store> getStore();
|
2017-03-16 13:25:54 +00:00
|
|
|
|
virtual ref<Store> createStore();
|
2016-02-09 20:28:29 +00:00
|
|
|
|
virtual void run(ref<Store>) = 0;
|
2017-04-25 09:20:37 +00:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::shared_ptr<Store> _store;
|
2016-02-09 20:28:29 +00:00
|
|
|
|
};
|
|
|
|
|
|
2017-09-06 14:03:22 +00:00
|
|
|
|
struct Buildable
|
|
|
|
|
{
|
|
|
|
|
Path drvPath; // may be empty
|
|
|
|
|
std::map<std::string, Path> outputs;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef std::vector<Buildable> Buildables;
|
2017-07-14 15:10:13 +00:00
|
|
|
|
|
2017-04-25 10:06:32 +00:00
|
|
|
|
struct Installable
|
|
|
|
|
{
|
|
|
|
|
virtual std::string what() = 0;
|
|
|
|
|
|
2017-09-06 14:03:22 +00:00
|
|
|
|
virtual Buildables toBuildables()
|
2017-04-25 10:06:32 +00:00
|
|
|
|
{
|
2017-07-30 11:27:57 +00:00
|
|
|
|
throw Error("argument '%s' cannot be built", what());
|
2017-04-25 10:06:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-06 14:03:22 +00:00
|
|
|
|
Buildable toBuildable();
|
|
|
|
|
|
2017-04-25 10:06:32 +00:00
|
|
|
|
virtual Value * toValue(EvalState & state)
|
|
|
|
|
{
|
2017-07-30 11:27:57 +00:00
|
|
|
|
throw Error("argument '%s' cannot be evaluated", what());
|
2017-04-25 10:06:32 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-10-24 10:45:11 +00:00
|
|
|
|
struct SourceExprCommand : virtual Args, StoreCommand, MixEvalArgs
|
2017-04-25 10:06:32 +00:00
|
|
|
|
{
|
|
|
|
|
Path file;
|
|
|
|
|
|
2017-10-24 10:45:11 +00:00
|
|
|
|
SourceExprCommand();
|
2017-04-25 10:06:32 +00:00
|
|
|
|
|
|
|
|
|
/* Return a value representing the Nix expression from which we
|
|
|
|
|
are installing. This is either the file specified by ‘--file’,
|
|
|
|
|
or an attribute set constructed from $NIX_PATH, e.g. ‘{ nixpkgs
|
|
|
|
|
= import ...; bla = import ...; }’. */
|
|
|
|
|
Value * getSourceExpr(EvalState & state);
|
|
|
|
|
|
2017-07-17 17:02:56 +00:00
|
|
|
|
ref<EvalState> getEvalState();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<EvalState> evalState;
|
|
|
|
|
|
|
|
|
|
Value * vSourceExpr = 0;
|
|
|
|
|
};
|
|
|
|
|
|
2017-09-10 13:58:30 +00:00
|
|
|
|
enum RealiseMode { Build, NoBuild, DryRun };
|
|
|
|
|
|
2017-07-17 17:02:56 +00:00
|
|
|
|
/* A command that operates on a list of "installables", which can be
|
|
|
|
|
store paths, attribute paths, Nix expressions, etc. */
|
|
|
|
|
struct InstallablesCommand : virtual Args, SourceExprCommand
|
|
|
|
|
{
|
|
|
|
|
std::vector<std::shared_ptr<Installable>> installables;
|
|
|
|
|
|
|
|
|
|
InstallablesCommand()
|
|
|
|
|
{
|
|
|
|
|
expectArgs("installables", &_installables);
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-25 10:06:32 +00:00
|
|
|
|
void prepare() override;
|
|
|
|
|
|
2017-05-02 13:28:35 +00:00
|
|
|
|
virtual bool useDefaultInstallables() { return true; }
|
|
|
|
|
|
2017-04-25 10:06:32 +00:00
|
|
|
|
private:
|
|
|
|
|
|
2017-10-24 10:45:11 +00:00
|
|
|
|
std::vector<std::string> _installables;
|
2017-04-25 10:06:32 +00:00
|
|
|
|
};
|
|
|
|
|
|
2017-08-29 14:18:00 +00:00
|
|
|
|
struct InstallableCommand : virtual Args, SourceExprCommand
|
|
|
|
|
{
|
|
|
|
|
std::shared_ptr<Installable> installable;
|
|
|
|
|
|
|
|
|
|
InstallableCommand()
|
|
|
|
|
{
|
|
|
|
|
expectArg("installable", &_installable);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void prepare() override;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
std::string _installable;
|
|
|
|
|
};
|
|
|
|
|
|
2017-04-25 11:20:26 +00:00
|
|
|
|
/* A command that operates on zero or more store paths. */
|
|
|
|
|
struct StorePathsCommand : public InstallablesCommand
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
bool recursive = false;
|
|
|
|
|
bool all = false;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
2017-09-27 16:28:54 +00:00
|
|
|
|
StorePathsCommand(bool recursive = false);
|
2017-04-25 11:20:26 +00:00
|
|
|
|
|
|
|
|
|
using StoreCommand::run;
|
|
|
|
|
|
|
|
|
|
virtual void run(ref<Store> store, Paths storePaths) = 0;
|
|
|
|
|
|
|
|
|
|
void run(ref<Store> store) override;
|
2017-05-02 13:28:35 +00:00
|
|
|
|
|
|
|
|
|
bool useDefaultInstallables() override { return !all; }
|
2017-04-25 11:20:26 +00:00
|
|
|
|
};
|
|
|
|
|
|
2017-05-04 12:16:26 +00:00
|
|
|
|
/* A command that operates on exactly one store path. */
|
|
|
|
|
struct StorePathCommand : public InstallablesCommand
|
|
|
|
|
{
|
|
|
|
|
using StoreCommand::run;
|
|
|
|
|
|
|
|
|
|
virtual void run(ref<Store> store, const Path & storePath) = 0;
|
|
|
|
|
|
|
|
|
|
void run(ref<Store> store) override;
|
|
|
|
|
};
|
|
|
|
|
|
2016-02-09 20:28:29 +00:00
|
|
|
|
typedef std::map<std::string, ref<Command>> Commands;
|
|
|
|
|
|
|
|
|
|
/* An argument parser that supports multiple subcommands,
|
2016-11-25 23:37:43 +00:00
|
|
|
|
i.e. ‘<command> <subcommand>’. */
|
2016-03-14 11:37:30 +00:00
|
|
|
|
class MultiCommand : virtual Args
|
2016-02-09 20:28:29 +00:00
|
|
|
|
{
|
2016-03-14 11:37:30 +00:00
|
|
|
|
public:
|
2016-02-09 20:28:29 +00:00
|
|
|
|
Commands commands;
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<Command> command;
|
|
|
|
|
|
|
|
|
|
MultiCommand(const Commands & commands);
|
|
|
|
|
|
|
|
|
|
void printHelp(const string & programName, std::ostream & out) override;
|
|
|
|
|
|
|
|
|
|
bool processFlag(Strings::iterator & pos, Strings::iterator end) override;
|
|
|
|
|
|
|
|
|
|
bool processArgs(const Strings & args, bool finish) override;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* A helper class for registering commands globally. */
|
|
|
|
|
struct RegisterCommand
|
|
|
|
|
{
|
|
|
|
|
static Commands * commands;
|
|
|
|
|
|
|
|
|
|
RegisterCommand(ref<Command> command)
|
|
|
|
|
{
|
|
|
|
|
if (!commands) commands = new Commands;
|
|
|
|
|
commands->emplace(command->name(), command);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-09-10 13:58:30 +00:00
|
|
|
|
std::shared_ptr<Installable> parseInstallable(
|
|
|
|
|
SourceExprCommand & cmd, ref<Store> store, const std::string & installable,
|
|
|
|
|
bool useDefaultInstallables);
|
|
|
|
|
|
|
|
|
|
Buildables toBuildables(ref<Store> store, RealiseMode mode,
|
|
|
|
|
std::vector<std::shared_ptr<Installable>> installables);
|
|
|
|
|
|
|
|
|
|
PathSet toStorePaths(ref<Store> store, RealiseMode mode,
|
|
|
|
|
std::vector<std::shared_ptr<Installable>> installables);
|
|
|
|
|
|
|
|
|
|
Path toStorePath(ref<Store> store, RealiseMode mode,
|
|
|
|
|
std::shared_ptr<Installable> installable);
|
|
|
|
|
|
Add "nix show-derivation"
This debug command prints a store derivation in JSON format. For
example:
$ nix show-derivation nixpkgs.hello
{
"/nix/store/ayjwpwwiyy04nh9z71rsdgd3q7bra7ch-hello-2.10.drv": {
"outputs": {
"out": {
"path": "/nix/store/w5w4v29ql0qwqhczkdxs94ix2lh7ibgs-hello-2.10"
}
},
"inputSrcs": [
"/nix/store/9krlzvny65gdc8s7kpb6lkx8cd02c25b-default-builder.sh"
],
"inputDrvs": {
"/nix/store/13839aqdf6x4k3b785rw5f2l7857l6y3-bash-4.4-p12.drv": [
"out"
],
"/nix/store/vgdx7fdc7d4iirmnwj2py1nrvr5qwzj7-hello-2.10.tar.gz.drv": [
"out"
],
"/nix/store/x3kkd0vsqfflbvwf1055l9mr39bg0ms0-stdenv.drv": [
"out"
]
},
"platform": "x86_64-linux",
"builder": "/nix/store/qp5fw57d38bd1n07ss4zxh88zg67c3vg-bash-4.4-p12/bin/bash",
"args": [
"-e",
"/nix/store/9krlzvny65gdc8s7kpb6lkx8cd02c25b-default-builder.sh"
],
"env": {
"buildInputs": "",
"builder": "/nix/store/qp5fw57d38bd1n07ss4zxh88zg67c3vg-bash-4.4-p12/bin/bash",
"configureFlags": "",
"doCheck": "1",
"name": "hello-2.10",
"nativeBuildInputs": "",
"out": "/nix/store/w5w4v29ql0qwqhczkdxs94ix2lh7ibgs-hello-2.10",
"propagatedBuildInputs": "",
"propagatedNativeBuildInputs": "",
"src": "/nix/store/3x7dwzq014bblazs7kq20p9hyzz0qh8g-hello-2.10.tar.gz",
"stdenv": "/nix/store/6zngq1rdh0ans9qyckqimqibgnlvlfrm-stdenv",
"system": "x86_64-linux"
}
}
}
This removes the need for pp-aterm.
2017-09-25 11:43:35 +00:00
|
|
|
|
PathSet toDerivations(ref<Store> store,
|
|
|
|
|
std::vector<std::shared_ptr<Installable>> installables,
|
|
|
|
|
bool useDeriver = false);
|
|
|
|
|
|
2016-02-09 20:28:29 +00:00
|
|
|
|
}
|