1
- #include " nix/cmd/command.hh"
2
- #include " nix/cmd/installable-flake.hh"
1
+ #include " flake-command.hh"
3
2
#include " nix/main/common-args.hh"
4
3
#include " nix/main/shared.hh"
5
4
#include " nix/expr/eval.hh"
6
5
#include " nix/expr/eval-inline.hh"
7
6
#include " nix/expr/eval-settings.hh"
8
- #include " nix/flake/flake.hh"
9
7
#include " nix/expr/get-drvs.hh"
10
8
#include " nix/util/signals.hh"
11
9
#include " nix/store/store-open.hh"
20
18
#include " nix/fetchers/fetch-to-store.hh"
21
19
#include " nix/store/local-fs-store.hh"
22
20
#include " nix/expr/parallel-eval.hh"
23
- #include " nix/util/thread-pool.hh"
24
- #include " nix/store/filetransfer.hh"
25
21
26
22
#include < filesystem>
27
23
#include < nlohmann/json.hpp>
@@ -36,43 +32,36 @@ using namespace nix::flake;
36
32
using json = nlohmann::json;
37
33
38
34
struct CmdFlakeUpdate ;
39
- class FlakeCommand : virtual Args, public MixFlakeOptions
40
- {
41
- protected:
42
- std::string flakeUrl = " ." ;
43
-
44
- public:
45
35
46
- FlakeCommand ()
47
- {
48
- expectArgs ({
49
- .label = " flake-url" ,
50
- .optional = true ,
51
- .handler = {&flakeUrl},
52
- .completer = {[&](AddCompletions & completions, size_t , std::string_view prefix) {
53
- completeFlakeRef (completions, getStore (), prefix);
54
- }}
55
- });
56
- }
36
+ FlakeCommand:: FlakeCommand ()
37
+ {
38
+ expectArgs ({
39
+ .label = " flake-url" ,
40
+ .optional = true ,
41
+ .handler = {&flakeUrl},
42
+ .completer = {[&](AddCompletions & completions, size_t , std::string_view prefix) {
43
+ completeFlakeRef (completions, getStore (), prefix);
44
+ }}
45
+ });
46
+ }
57
47
58
- FlakeRef getFlakeRef ()
59
- {
60
- return parseFlakeRef (fetchSettings, flakeUrl, std::filesystem::current_path ().string ()); // FIXME
61
- }
48
+ FlakeRef FlakeCommand:: getFlakeRef ()
49
+ {
50
+ return parseFlakeRef (fetchSettings, flakeUrl, std::filesystem::current_path ().string ()); // FIXME
51
+ }
62
52
63
- LockedFlake lockFlake ()
64
- {
65
- return flake::lockFlake (flakeSettings, *getEvalState (), getFlakeRef (), lockFlags);
66
- }
53
+ LockedFlake FlakeCommand:: lockFlake ()
54
+ {
55
+ return flake::lockFlake (flakeSettings, *getEvalState (), getFlakeRef (), lockFlags);
56
+ }
67
57
68
- std::vector<FlakeRef> getFlakeRefsForCompletion () override
69
- {
70
- return {
71
- // Like getFlakeRef but with expandTilde calld first
72
- parseFlakeRef (fetchSettings, expandTilde (flakeUrl), std::filesystem::current_path ().string ())
73
- };
74
- }
75
- };
58
+ std::vector<FlakeRef> FlakeCommand::getFlakeRefsForCompletion ()
59
+ {
60
+ return {
61
+ // Like getFlakeRef but with expandTilde calld first
62
+ parseFlakeRef (fetchSettings, expandTilde (flakeUrl), std::filesystem::current_path ().string ())
63
+ };
64
+ }
76
65
77
66
struct CmdFlakeUpdate : FlakeCommand
78
67
{
@@ -1150,59 +1139,6 @@ struct CmdFlakeArchive : FlakeCommand, MixJSON, MixDryRun
1150
1139
}
1151
1140
};
1152
1141
1153
- struct CmdFlakePrefetchInputs : FlakeCommand
1154
- {
1155
- std::string description () override
1156
- {
1157
- return " fetch the inputs of a flake" ;
1158
- }
1159
-
1160
- std::string doc () override
1161
- {
1162
- return
1163
- #include " flake-prefetch-inputs.md"
1164
- ;
1165
- }
1166
-
1167
- void run (nix::ref<nix::Store> store) override
1168
- {
1169
- auto flake = lockFlake ();
1170
-
1171
- ThreadPool pool{fileTransferSettings.httpConnections };
1172
-
1173
- struct State
1174
- {
1175
- std::set<const Node *> done;
1176
- };
1177
-
1178
- Sync<State> state_;
1179
-
1180
- std::function<void (const Node & node)> visit;
1181
- visit = [&](const Node & node)
1182
- {
1183
- if (!state_.lock ()->done .insert (&node).second )
1184
- return ;
1185
-
1186
- if (auto lockedNode = dynamic_cast <const LockedNode *>(&node)) {
1187
- Activity act (*logger, lvlInfo, actUnknown,
1188
- fmt (" fetching '%s'" , lockedNode->lockedRef ));
1189
- auto accessor = lockedNode->lockedRef .input .getAccessor (store).first ;
1190
- if (!evalSettings.lazyTrees )
1191
- fetchToStore (*store, accessor, FetchMode::Copy, lockedNode->lockedRef .input .getName ());
1192
- }
1193
-
1194
- for (auto & [inputName, input] : node.inputs ) {
1195
- if (auto inputNode = std::get_if<0 >(&input))
1196
- pool.enqueue (std::bind (visit, **inputNode));
1197
- }
1198
- };
1199
-
1200
- pool.enqueue (std::bind (visit, *flake.lockFile .root ));
1201
-
1202
- pool.process ();
1203
- }
1204
- };
1205
-
1206
1142
struct CmdFlakeShow : FlakeCommand, MixJSON
1207
1143
{
1208
1144
bool showLegacy = false ;
@@ -1546,22 +1482,7 @@ struct CmdFlakePrefetch : FlakeCommand, MixJSON
1546
1482
struct CmdFlake : NixMultiCommand
1547
1483
{
1548
1484
CmdFlake ()
1549
- : NixMultiCommand(
1550
- " flake" ,
1551
- {
1552
- {" update" , []() { return make_ref<CmdFlakeUpdate>(); }},
1553
- {" lock" , []() { return make_ref<CmdFlakeLock>(); }},
1554
- {" metadata" , []() { return make_ref<CmdFlakeMetadata>(); }},
1555
- {" info" , []() { return make_ref<CmdFlakeInfo>(); }},
1556
- {" check" , []() { return make_ref<CmdFlakeCheck>(); }},
1557
- {" init" , []() { return make_ref<CmdFlakeInit>(); }},
1558
- {" new" , []() { return make_ref<CmdFlakeNew>(); }},
1559
- {" clone" , []() { return make_ref<CmdFlakeClone>(); }},
1560
- {" archive" , []() { return make_ref<CmdFlakeArchive>(); }},
1561
- {" prefetch-inputs" , []() { return make_ref<CmdFlakePrefetchInputs>(); }},
1562
- {" show" , []() { return make_ref<CmdFlakeShow>(); }},
1563
- {" prefetch" , []() { return make_ref<CmdFlakePrefetch>(); }},
1564
- })
1485
+ : NixMultiCommand(" flake" , RegisterCommand::getCommandsFor({" flake" }))
1565
1486
{
1566
1487
}
1567
1488
@@ -1579,3 +1500,14 @@ struct CmdFlake : NixMultiCommand
1579
1500
};
1580
1501
1581
1502
static auto rCmdFlake = registerCommand<CmdFlake>(" flake" );
1503
+ static auto rCmdFlakeArchive = registerCommand2<CmdFlakeArchive>({" flake" , " archive" });
1504
+ static auto rCmdFlakeCheck = registerCommand2<CmdFlakeCheck>({" flake" , " check" });
1505
+ static auto rCmdFlakeClone = registerCommand2<CmdFlakeClone>({" flake" , " clone" });
1506
+ static auto rCmdFlakeInfo = registerCommand2<CmdFlakeInfo>({" flake" , " info" });
1507
+ static auto rCmdFlakeInit = registerCommand2<CmdFlakeInit>({" flake" , " init" });
1508
+ static auto rCmdFlakeLock = registerCommand2<CmdFlakeLock>({" flake" , " lock" });
1509
+ static auto rCmdFlakeMetadata = registerCommand2<CmdFlakeMetadata>({" flake" , " metadata" });
1510
+ static auto rCmdFlakeNew = registerCommand2<CmdFlakeNew>({" flake" , " new" });
1511
+ static auto rCmdFlakePrefetch = registerCommand2<CmdFlakePrefetch>({" flake" , " prefetch" });
1512
+ static auto rCmdFlakeShow = registerCommand2<CmdFlakeShow>({" flake" , " show" });
1513
+ static auto rCmdFlakeUpdate = registerCommand2<CmdFlakeUpdate>({" flake" , " update" });
0 commit comments