mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-23 14:36:16 +02:00
Move code around
This commit is contained in:
parent
5446eae949
commit
0bc8f1669d
3 changed files with 216 additions and 189 deletions
|
@ -1,15 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include "installables.hh"
|
||||
#include "args.hh"
|
||||
#include "common-eval-args.hh"
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace nix {
|
||||
|
||||
extern std::string programPath;
|
||||
|
||||
struct Value;
|
||||
class Bindings;
|
||||
class EvalState;
|
||||
class Store;
|
||||
|
||||
|
@ -30,51 +30,6 @@ private:
|
|||
std::shared_ptr<Store> _store;
|
||||
};
|
||||
|
||||
struct Buildable
|
||||
{
|
||||
Path drvPath; // may be empty
|
||||
std::map<std::string, Path> outputs;
|
||||
};
|
||||
|
||||
typedef std::vector<Buildable> Buildables;
|
||||
|
||||
struct App
|
||||
{
|
||||
PathSet context;
|
||||
Path program;
|
||||
// FIXME: add args, sandbox settings, metadata, ...
|
||||
|
||||
App(EvalState & state, Value & vApp);
|
||||
};
|
||||
|
||||
struct Installable
|
||||
{
|
||||
virtual ~Installable() { }
|
||||
|
||||
virtual std::string what() = 0;
|
||||
|
||||
virtual Buildables toBuildables()
|
||||
{
|
||||
throw Error("argument '%s' cannot be built", what());
|
||||
}
|
||||
|
||||
Buildable toBuildable();
|
||||
|
||||
App toApp(EvalState & state);
|
||||
|
||||
virtual Value * toValue(EvalState & state)
|
||||
{
|
||||
throw Error("argument '%s' cannot be evaluated", what());
|
||||
}
|
||||
|
||||
/* Return a value only if this installable is a store path or a
|
||||
symlink to it. */
|
||||
virtual std::optional<Path> getStorePath()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
struct EvalCommand : virtual StoreCommand, MixEvalArgs
|
||||
{
|
||||
ref<EvalState> getEvalState();
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include "installables.hh"
|
||||
#include "command.hh"
|
||||
#include "attr-path.hh"
|
||||
#include "common-eval-args.hh"
|
||||
|
@ -111,13 +112,7 @@ struct InstallableStorePath : Installable
|
|||
}
|
||||
};
|
||||
|
||||
struct InstallableValue : Installable
|
||||
{
|
||||
SourceExprCommand & cmd;
|
||||
|
||||
InstallableValue(SourceExprCommand & cmd) : cmd(cmd) { }
|
||||
|
||||
virtual std::vector<flake::EvalCache::Derivation> toDerivations()
|
||||
std::vector<flake::EvalCache::Derivation> InstallableValue::toDerivations()
|
||||
{
|
||||
auto state = cmd.getEvalState();
|
||||
|
||||
|
@ -140,7 +135,7 @@ struct InstallableValue : Installable
|
|||
return res;
|
||||
}
|
||||
|
||||
Buildables toBuildables() override
|
||||
Buildables InstallableValue::toBuildables()
|
||||
{
|
||||
Buildables res;
|
||||
|
||||
|
@ -169,7 +164,6 @@ struct InstallableValue : Installable
|
|||
} else
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
struct InstallableExpr : InstallableValue
|
||||
{
|
||||
|
@ -254,25 +248,7 @@ void makeFlakeClosureGCRoot(Store & store,
|
|||
store.addIndirectRoot(symlink);
|
||||
}
|
||||
|
||||
struct InstallableFlake : InstallableValue
|
||||
{
|
||||
FlakeRef flakeRef;
|
||||
Strings attrPaths;
|
||||
Strings prefixes;
|
||||
|
||||
InstallableFlake(SourceExprCommand & cmd, FlakeRef && flakeRef, Strings attrPaths)
|
||||
: InstallableValue(cmd), flakeRef(flakeRef), attrPaths(std::move(attrPaths))
|
||||
{ }
|
||||
|
||||
InstallableFlake(SourceExprCommand & cmd, FlakeRef && flakeRef,
|
||||
std::string attrPath, Strings && prefixes)
|
||||
: InstallableValue(cmd), flakeRef(flakeRef), attrPaths{attrPath},
|
||||
prefixes(prefixes)
|
||||
{ }
|
||||
|
||||
std::string what() override { return flakeRef.to_string() + ":" + *attrPaths.begin(); }
|
||||
|
||||
std::vector<std::string> getActualAttrPaths()
|
||||
std::vector<std::string> InstallableFlake::getActualAttrPaths()
|
||||
{
|
||||
std::vector<std::string> res;
|
||||
|
||||
|
@ -285,7 +261,7 @@ struct InstallableFlake : InstallableValue
|
|||
return res;
|
||||
}
|
||||
|
||||
Value * getFlakeOutputs(EvalState & state, const flake::ResolvedFlake & resFlake)
|
||||
Value * InstallableFlake::getFlakeOutputs(EvalState & state, const flake::ResolvedFlake & resFlake)
|
||||
{
|
||||
auto vFlake = state.allocValue();
|
||||
|
||||
|
@ -301,7 +277,7 @@ struct InstallableFlake : InstallableValue
|
|||
return (*aOutputs)->value;
|
||||
}
|
||||
|
||||
std::vector<flake::EvalCache::Derivation> toDerivations() override
|
||||
std::vector<flake::EvalCache::Derivation> InstallableFlake::toDerivations()
|
||||
{
|
||||
auto state = cmd.getEvalState();
|
||||
|
||||
|
@ -350,7 +326,7 @@ struct InstallableFlake : InstallableValue
|
|||
flakeRef, concatStringsSep(", ", quoteStrings(attrPaths)));
|
||||
}
|
||||
|
||||
Value * toValue(EvalState & state) override
|
||||
Value * InstallableFlake::toValue(EvalState & state)
|
||||
{
|
||||
auto resFlake = resolveFlake(state, flakeRef, cmd.getLockFileMode());
|
||||
|
||||
|
@ -370,7 +346,6 @@ struct InstallableFlake : InstallableValue
|
|||
throw Error("flake '%s' does not provide attribute %s",
|
||||
flakeRef, concatStringsSep(", ", quoteStrings(attrPaths)));
|
||||
}
|
||||
};
|
||||
|
||||
// FIXME: extend
|
||||
std::string attrRegex = R"([A-Za-z_][A-Za-z0-9-_+]*)";
|
||||
|
|
97
src/nix/installables.hh
Normal file
97
src/nix/installables.hh
Normal file
|
@ -0,0 +1,97 @@
|
|||
#pragma once
|
||||
|
||||
#include "util.hh"
|
||||
#include "flake/eval-cache.hh"
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace nix {
|
||||
|
||||
struct Value;
|
||||
class EvalState;
|
||||
class SourceExprCommand;
|
||||
|
||||
struct Buildable
|
||||
{
|
||||
Path drvPath; // may be empty
|
||||
std::map<std::string, Path> outputs;
|
||||
};
|
||||
|
||||
typedef std::vector<Buildable> Buildables;
|
||||
|
||||
struct App
|
||||
{
|
||||
PathSet context;
|
||||
Path program;
|
||||
// FIXME: add args, sandbox settings, metadata, ...
|
||||
|
||||
App(EvalState & state, Value & vApp);
|
||||
};
|
||||
|
||||
struct Installable
|
||||
{
|
||||
virtual ~Installable() { }
|
||||
|
||||
virtual std::string what() = 0;
|
||||
|
||||
virtual Buildables toBuildables()
|
||||
{
|
||||
throw Error("argument '%s' cannot be built", what());
|
||||
}
|
||||
|
||||
Buildable toBuildable();
|
||||
|
||||
App toApp(EvalState & state);
|
||||
|
||||
virtual Value * toValue(EvalState & state)
|
||||
{
|
||||
throw Error("argument '%s' cannot be evaluated", what());
|
||||
}
|
||||
|
||||
/* Return a value only if this installable is a store path or a
|
||||
symlink to it. */
|
||||
virtual std::optional<Path> getStorePath()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
struct InstallableValue : Installable
|
||||
{
|
||||
SourceExprCommand & cmd;
|
||||
|
||||
InstallableValue(SourceExprCommand & cmd) : cmd(cmd) { }
|
||||
|
||||
virtual std::vector<flake::EvalCache::Derivation> toDerivations();
|
||||
|
||||
Buildables toBuildables() override;
|
||||
};
|
||||
|
||||
struct InstallableFlake : InstallableValue
|
||||
{
|
||||
FlakeRef flakeRef;
|
||||
Strings attrPaths;
|
||||
Strings prefixes;
|
||||
|
||||
InstallableFlake(SourceExprCommand & cmd, FlakeRef && flakeRef, Strings attrPaths)
|
||||
: InstallableValue(cmd), flakeRef(flakeRef), attrPaths(std::move(attrPaths))
|
||||
{ }
|
||||
|
||||
InstallableFlake(SourceExprCommand & cmd, FlakeRef && flakeRef,
|
||||
std::string attrPath, Strings && prefixes)
|
||||
: InstallableValue(cmd), flakeRef(flakeRef), attrPaths{attrPath},
|
||||
prefixes(prefixes)
|
||||
{ }
|
||||
|
||||
std::string what() override { return flakeRef.to_string() + ":" + *attrPaths.begin(); }
|
||||
|
||||
std::vector<std::string> getActualAttrPaths();
|
||||
|
||||
Value * getFlakeOutputs(EvalState & state, const flake::ResolvedFlake & resFlake);
|
||||
|
||||
std::vector<flake::EvalCache::Derivation> toDerivations() override;
|
||||
|
||||
Value * toValue(EvalState & state) override;
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in a new issue