aboutsummaryrefslogtreecommitdiff
path: root/src/nix
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2018-11-29 19:18:36 +0100
committerEelco Dolstra <edolstra@gmail.com>2019-02-11 12:00:13 +0100
commit7a5cf31060289de61370643937277b5d0d5d178c (patch)
tree9b5b2060a0f9b65d3cfae2ad826015a9ba1d77a8 /src/nix
parentf216c76c56cdffb5214d074a7d44812843dd174f (diff)
Initial flake support
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/flake.cc65
-rw-r--r--src/nix/installables.cc39
2 files changed, 67 insertions, 37 deletions
diff --git a/src/nix/flake.cc b/src/nix/flake.cc
new file mode 100644
index 000000000..98cd90c64
--- /dev/null
+++ b/src/nix/flake.cc
@@ -0,0 +1,65 @@
+#include "command.hh"
+#include "common-args.hh"
+#include "shared.hh"
+#include "progress-bar.hh"
+#include "eval.hh"
+
+using namespace nix;
+
+struct CmdFlakeList : StoreCommand, MixEvalArgs
+{
+ std::string name() override
+ {
+ return "list";
+ }
+
+ std::string description() override
+ {
+ return "list available Nix flakes";
+ }
+
+ void run(nix::ref<nix::Store> store) override
+ {
+ auto evalState = std::make_shared<EvalState>(searchPath, store);
+
+ auto registry = evalState->getFlakeRegistry();
+
+ stopProgressBar();
+
+ for (auto & entry : registry.entries) {
+ std::cout << entry.first << " " << entry.second.uri << "\n";
+ }
+ }
+};
+
+struct CmdFlake : virtual MultiCommand, virtual Command
+{
+ CmdFlake()
+ : MultiCommand({make_ref<CmdFlakeList>()})
+ {
+ }
+
+ std::string name() override
+ {
+ return "flake";
+ }
+
+ std::string description() override
+ {
+ return "manage Nix flakes";
+ }
+
+ void run() override
+ {
+ if (!command)
+ throw UsageError("'nix flake' requires a sub-command.");
+ command->run();
+ }
+
+ void printHelp(const string & programName, std::ostream & out) override
+ {
+ MultiCommand::printHelp(programName, out);
+ }
+};
+
+static RegisterCommand r1(make_ref<CmdFlake>());
diff --git a/src/nix/installables.cc b/src/nix/installables.cc
index 0c1ad3ab3..9b7b96c25 100644
--- a/src/nix/installables.cc
+++ b/src/nix/installables.cc
@@ -26,47 +26,12 @@ Value * SourceExprCommand::getSourceExpr(EvalState & state)
{
if (vSourceExpr) return vSourceExpr;
- auto sToplevel = state.symbols.create("_toplevel");
-
vSourceExpr = state.allocValue();
if (file != "")
state.evalFile(lookupFileArg(state, file), *vSourceExpr);
-
- else {
-
- /* Construct the installation source from $NIX_PATH. */
-
- auto searchPath = state.getSearchPath();
-
- state.mkAttrs(*vSourceExpr, searchPath.size() + 1);
-
- mkBool(*state.allocAttr(*vSourceExpr, sToplevel), true);
-
- std::unordered_set<std::string> seen;
-
- for (auto & i : searchPath) {
- if (i.first == "") continue;
- if (seen.count(i.first)) continue;
- seen.insert(i.first);
-#if 0
- auto res = state.resolveSearchPathElem(i);
- if (!res.first) continue;
- if (!pathExists(res.second)) continue;
- mkApp(*state.allocAttr(*vSourceExpr, state.symbols.create(i.first)),
- state.getBuiltin("import"),
- mkString(*state.allocValue(), res.second));
-#endif
- Value * v1 = state.allocValue();
- mkPrimOpApp(*v1, state.getBuiltin("findFile"), state.getBuiltin("nixPath"));
- Value * v2 = state.allocValue();
- mkApp(*v2, *v1, mkString(*state.allocValue(), i.first));
- mkApp(*state.allocAttr(*vSourceExpr, state.symbols.create(i.first)),
- state.getBuiltin("import"), *v2);
- }
-
- vSourceExpr->attrs->sort();
- }
+ else
+ state.evalFile(lookupFileArg(state, "<nix/default-installation-source.nix>"), *vSourceExpr);
return vSourceExpr;
}