99#include < sys/time.h>
1010#endif
1111
12+ #include " machines.hh"
1213#include " shared.hh"
1314#include " pathlocks.hh"
1415#include " globals.hh"
@@ -22,92 +23,6 @@ using std::cin;
2223static void handleAlarm (int sig) {
2324}
2425
25- class Machine {
26- const std::set<string> supportedFeatures;
27- const std::set<string> mandatoryFeatures;
28-
29- public:
30- const string storeUri;
31- const std::vector<string> systemTypes;
32- const string sshKey;
33- const unsigned int maxJobs;
34- const unsigned int speedFactor;
35- bool enabled = true ;
36-
37- bool allSupported (const std::set<string> & features) const {
38- return std::all_of (features.begin (), features.end (),
39- [&](const string & feature) {
40- return supportedFeatures.count (feature) ||
41- mandatoryFeatures.count (feature);
42- });
43- }
44-
45- bool mandatoryMet (const std::set<string> & features) const {
46- return std::all_of (mandatoryFeatures.begin (), mandatoryFeatures.end (),
47- [&](const string & feature) {
48- return features.count (feature);
49- });
50- }
51-
52- Machine (decltype (storeUri) storeUri,
53- decltype (systemTypes) systemTypes,
54- decltype (sshKey) sshKey,
55- decltype (maxJobs) maxJobs,
56- decltype (speedFactor) speedFactor,
57- decltype (supportedFeatures) supportedFeatures,
58- decltype (mandatoryFeatures) mandatoryFeatures) :
59- supportedFeatures (supportedFeatures),
60- mandatoryFeatures (mandatoryFeatures),
61- storeUri (
62- // Backwards compatibility: if the URI is a hostname,
63- // prepend ssh://.
64- storeUri.find(" ://" ) != std::string::npos || hasPrefix(storeUri, " local" ) || hasPrefix(storeUri, " remote" ) || hasPrefix(storeUri, " auto" )
65- ? storeUri
66- : " ssh://" + storeUri),
67- systemTypes (systemTypes),
68- sshKey (sshKey),
69- maxJobs (maxJobs),
70- speedFactor (std::max(1U , speedFactor))
71- {}
72- };
73-
74- static std::vector<Machine> readConf ()
75- {
76- auto conf = getEnv (" NIX_REMOTE_SYSTEMS" , SYSCONFDIR " /nix/machines" );
77-
78- auto machines = std::vector<Machine>{};
79- auto lines = std::vector<string>{};
80- try {
81- lines = tokenizeString<std::vector<string>>(readFile (conf), " \n " );
82- } catch (const SysError & e) {
83- if (e.errNo != ENOENT)
84- throw ;
85- }
86- for (auto line : lines) {
87- chomp (line);
88- line.erase (std::find (line.begin (), line.end (), ' #' ), line.end ());
89- if (line.empty ()) {
90- continue ;
91- }
92- auto tokens = tokenizeString<std::vector<string>>(line);
93- auto sz = tokens.size ();
94- if (sz < 1 )
95- throw FormatError (" bad machines.conf file ‘%1%’" , conf);
96- machines.emplace_back (tokens[0 ],
97- sz >= 2 ? tokenizeString<std::vector<string>>(tokens[1 ], " ," ) : std::vector<string>{settings.thisSystem },
98- sz >= 3 ? tokens[2 ] : " " ,
99- sz >= 4 ? std::stoull (tokens[3 ]) : 1LL ,
100- sz >= 5 ? std::stoull (tokens[4 ]) : 1LL ,
101- sz >= 6 ?
102- tokenizeString<std::set<string>>(tokens[5 ], " ," ) :
103- std::set<string>{},
104- sz >= 7 ?
105- tokenizeString<std::set<string>>(tokens[6 ], " ," ) :
106- std::set<string>{});
107- }
108- return machines;
109- }
110-
11126std::string escapeUri (std::string uri)
11227{
11328 std::replace (uri.begin (), uri.end (), ' /' , ' _' );
@@ -147,7 +62,13 @@ int main (int argc, char * * argv)
14762 std::shared_ptr<Store> sshStore;
14863 AutoCloseFD bestSlotLock;
14964
150- auto machines = readConf ();
65+ Machines machines;
66+ try {
67+ parseMachines (readFile (getEnv (" NIX_REMOTE_SYSTEMS" , SYSCONFDIR " /nix/machines" )), machines);
68+ } catch (const SysError & e) {
69+ if (e.errNo != ENOENT)
70+ throw ;
71+ }
15172 debug (" got %d remote builders" , machines.size ());
15273
15374 if (machines.empty ()) {
0 commit comments