about summary refs log tree commit diff
path: root/src/nix/command.hh
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-04-25T10·06+0200
committerEelco Dolstra <edolstra@gmail.com>2017-04-25T10·07+0200
commitc769841bc4ecb9dd3d8456931fec78e102c3832f (patch)
treee6723ab7c0c9e2af87181ea787a60bb4a662cfaf /src/nix/command.hh
parent6267d748891b3c6e6a41b5bd1f6684ae8b88f31c (diff)
Move code around
Diffstat (limited to 'src/nix/command.hh')
-rw-r--r--src/nix/command.hh54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/nix/command.hh b/src/nix/command.hh
index bb667ee325ca..ee9485e5dd14 100644
--- a/src/nix/command.hh
+++ b/src/nix/command.hh
@@ -4,6 +4,9 @@
 
 namespace nix {
 
+struct Value;
+class EvalState;
+
 /* A command is an argument parser that can be executed by calling its
    run() method. */
 struct Command : virtual Args
@@ -61,6 +64,57 @@ public:
     void run(ref<Store> store) override;
 };
 
+struct Installable
+{
+    virtual std::string what() = 0;
+
+    virtual PathSet toBuildable()
+    {
+        throw Error("argument ‘%s’ cannot be built", what());
+    }
+
+    virtual Value * toValue(EvalState & state)
+    {
+        throw Error("argument ‘%s’ cannot be evaluated", what());
+    }
+};
+
+/* A command that operates on a list of "installables", which can be
+   store paths, attribute paths, Nix expressions, etc. */
+struct InstallablesCommand : virtual Args, StoreCommand
+{
+    std::vector<std::shared_ptr<Installable>> installables;
+    Path file;
+
+    InstallablesCommand()
+    {
+        mkFlag('f', "file", "file", "evaluate FILE rather than the default", &file);
+        expectArgs("installables", &_installables);
+    }
+
+    /* 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);
+
+    std::vector<std::shared_ptr<Installable>> parseInstallables(ref<Store> store, Strings installables);
+
+    PathSet buildInstallables(ref<Store> store, bool dryRun);
+
+    ref<EvalState> getEvalState();
+
+    void prepare() override;
+
+private:
+
+    Strings _installables;
+
+    std::shared_ptr<EvalState> evalState;
+
+    Value * vSourceExpr = 0;
+};
+
 typedef std::map<std::string, ref<Command>> Commands;
 
 /* An argument parser that supports multiple subcommands,