Nix 2.26.3
Nix, the purely functional package manager; unstable internal interfaces
 
Loading...
Searching...
No Matches
shared.hh
Go to the documentation of this file.
1#pragma once
3
4#include "file-descriptor.hh"
5#include "processes.hh"
6#include "args.hh"
7#include "args/root.hh"
8#include "common-args.hh"
9#include "path.hh"
10#include "derived-path.hh"
11
12#include <signal.h>
13
14namespace nix {
15
16int handleExceptions(const std::string & programName, std::function<void()> fun);
17
22void initNix(bool loadConfig = true);
23
24void parseCmdLine(int argc, char * * argv,
25 std::function<bool(Strings::iterator & arg, const Strings::iterator & end)> parseArg);
26
27void parseCmdLine(const std::string & programName, const Strings & args,
28 std::function<bool(Strings::iterator & arg, const Strings::iterator & end)> parseArg);
29
30void printVersion(const std::string & programName);
31
35void printGCWarning();
36
37class Store;
38
39void printMissing(
41 const std::vector<DerivedPath> & paths,
42 Verbosity lvl = lvlInfo);
43
44void printMissing(ref<Store> store, const StorePathSet & willBuild,
45 const StorePathSet & willSubstitute, const StorePathSet & unknown,
46 uint64_t downloadSize, uint64_t narSize, Verbosity lvl = lvlInfo);
47
48std::string getArg(const std::string & opt,
49 Strings::iterator & i, const Strings::iterator & end);
50
51template<class N> N getIntArg(const std::string & opt,
52 Strings::iterator & i, const Strings::iterator & end, bool allowUnit)
53{
54 ++i;
55 if (i == end) throw UsageError("'%1%' requires an argument", opt);
57}
58
59
60struct LegacyArgs : public MixCommonArgs, public RootArgs
61{
62 std::function<bool(Strings::iterator & arg, const Strings::iterator & end)> parseArg;
63
64 LegacyArgs(const std::string & programName,
65 std::function<bool(Strings::iterator & arg, const Strings::iterator & end)> parseArg);
66
67 bool processFlag(Strings::iterator & pos, Strings::iterator end) override;
68
69 bool processArgs(const Strings & args, bool finish) override;
70};
71
72
78class RunPager
79{
80public:
81 RunPager();
82 ~RunPager();
83
84private:
85#ifndef _WIN32 // TODO re-enable on Windows, once we can start processes.
86 Pid pid;
87#endif
88 Descriptor std_out;
89};
90
91extern volatile ::sig_atomic_t blockInt;
92
93
94/* GC helpers. */
95
96std::string showBytes(uint64_t bytes);
97
98struct GCResults;
99
100struct PrintFreed
101{
102 bool show;
103 const GCResults & results;
104 PrintFreed(bool show, const GCResults & results)
105 : show(show), results(results) { }
106 ~PrintFreed();
107};
108
109
110#ifndef _WIN32
115
131extern std::function<void(siginfo_t * info, void * ctx)> stackOverflowHandler;
132
139void defaultStackOverflowHandler(siginfo_t * info, void * ctx);
140#endif
141
142}
Definition processes.hh:28
Definition root.hh:31
Definition store-api.hh:169
Definition ref.hh:15
int Descriptor
Definition file-descriptor.hh:20
ChunkedVector< std::string, 8192 > store
Definition lexer.l:1011
PosIdx end
Definition lexer.l:5814
auto i
Definition lexer.l:2745
std::function< void(Sink &)> fun
Definition lexer.l:3485
std::vector< Expr * > args
Definition lexer.l:6126
void defaultStackOverflowHandler(siginfo_t *info, void *ctx)
void detectStackOverflow()
std::function< void(siginfo_t *info, void *ctx)> stackOverflowHandler
Definition gc-store.hh:60
bool processFlag(Strings::iterator &pos, Strings::iterator end) override
Definition shared.cc:260
bool processArgs(const Strings &args, bool finish) override
Definition shared.cc:269
N string2IntWithUnitPrefix(std::string_view s)
Definition util.hh:88