aboutsummaryrefslogtreecommitdiff
path: root/src/libcmd/installable-value.hh
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2023-02-05 12:16:17 -0500
committerJohn Ericson <John.Ericson@Obsidian.Systems>2023-03-16 20:06:46 -0400
commitc998e0172f31fd5707a8361962ec99b3ff9b1b10 (patch)
treec8556e4e261fb80faebe66558b5bcccf92d1b26f /src/libcmd/installable-value.hh
parentacd707acca8acbc276af5181c7724c70a6a69ad5 (diff)
Move value-only methods to `InstallableValue`
These methods would previously fail on the other `Installable`s, so moving them to this class is more correct as to where they actually work. Additionally, a `InstallableValueCommand` is created to make it easier (or rather no worse than before) to write commands that just work on `InstallableValue`s. Besides being a cleanup to avoid failing default methods, this gets us closer to https://github.com/NixOS/rfcs/pull/134.
Diffstat (limited to 'src/libcmd/installable-value.hh')
-rw-r--r--src/libcmd/installable-value.hh30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/libcmd/installable-value.hh b/src/libcmd/installable-value.hh
index c6cdc4797..682c8d942 100644
--- a/src/libcmd/installable-value.hh
+++ b/src/libcmd/installable-value.hh
@@ -4,11 +4,41 @@
namespace nix {
+struct App
+{
+ std::vector<DerivedPath> context;
+ Path program;
+ // FIXME: add args, sandbox settings, metadata, ...
+};
+
+struct UnresolvedApp
+{
+ App unresolved;
+ App resolve(ref<Store> evalStore, ref<Store> store);
+};
+
struct InstallableValue : Installable
{
ref<EvalState> state;
InstallableValue(ref<EvalState> state) : state(state) {}
+
+ virtual std::pair<Value *, PosIdx> toValue(EvalState & state) = 0;
+
+ /* Get a cursor to each value this Installable could refer to. However
+ if none exists, throw exception instead of returning empty vector. */
+ virtual std::vector<ref<eval_cache::AttrCursor>>
+ getCursors(EvalState & state);
+
+ /* Get the first and most preferred cursor this Installable could refer
+ to, or throw an exception if none exists. */
+ virtual ref<eval_cache::AttrCursor>
+ getCursor(EvalState & state);
+
+ UnresolvedApp toApp(EvalState & state);
+
+ static InstallableValue & require(Installable & installable);
+ static ref<InstallableValue> require(ref<Installable> installable);
};
}