Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
restricted-store.hh
Go to the documentation of this file.
1#pragma once
3
5#include "nix/util/sync.hh"
6
7#include <future>
8
9namespace nix {
10
11struct Builder;
12class LocalStore;
13struct LocalStoreConfig;
14class Worker;
15
30{
31private:
32 /* VTable anchor to avoid weak linkage of the vtable - it breaks
33 dynamic_cast across shared libraries on Darwin. */
34 virtual void anchor();
35
36public:
40 virtual const StorePathSet & originalPaths() = 0;
41
42 struct State
43 {
47 std::map<StorePath, std::shared_future<void>> addedPaths;
48
52 std::set<DrvOutput> addedDrvOutputs;
53 };
54
55 Sync<State> state_;
56
63 virtual bool isAllowed(const StorePath &) = 0;
64 virtual bool isAllowed(const DrvOutput & id) = 0;
65 bool isAllowed(const DerivedPath & id);
66
71 virtual bool shouldModifySandbox() = 0;
72
77 virtual void submitOutput(const SingleDerivedPath & path, const OutputName & output) = 0;
78
83 void addDependency(const StorePath & path)
84 {
85 if (isAllowed(path))
86 return;
87
88 std::promise<void> promise;
89
90 auto [future, shouldAdd] = [&]() -> std::pair<std::shared_future<void>, bool> {
91 auto state(state_.lock());
92 if (auto iter = state->addedPaths.find(path); iter != state->addedPaths.end()) {
93 return {iter->second, false};
94 }
95 auto [iter2, _] = state->addedPaths.emplace(path, promise.get_future().share());
96 return {iter2->second, true};
97 }();
98
99 /* Another daemon worker thread already started adding the dependency. Just wait for it
100 to complete. */
101 if (!shouldAdd) {
102 future.get();
103 return;
104 }
105
106 try {
108 addDependencyImpl(path);
109 promise.set_value();
110 } catch (...) {
111 /* Notify all other waiters that we are done. */
112 promise.set_exception(std::current_exception());
113 throw;
114 }
115 }
116
117 virtual ~RestrictionContext() = default;
118
119protected:
120
126 virtual void addDependencyImpl(const StorePath & path) = 0;
127};
128
133
139
140} // namespace nix
Definition local-store.hh:185
Definition path.hh:33
Definition worker.hh:110
Definition ref.hh:58
std::string OutputName
Definition outputs-spec.hh:18
ref< Builder > makeRestrictedBuilder(Worker &inner, RestrictionContext &context)
Definition restricted-store.cc:396
ref< Store > makeRestrictedStore(ref< LocalStoreConfig > config, ref< LocalStore > next, RestrictionContext &context)
Definition restricted-store.cc:200
Definition build.hh:17
Definition derived-path.hh:238
Definition realisation.hh:26
Definition local-store.hh:85
Definition restricted-store.hh:43
std::set< DrvOutput > addedDrvOutputs
Definition restricted-store.hh:52
std::map< StorePath, std::shared_future< void > > addedPaths
Definition restricted-store.hh:47
Definition restricted-store.hh:30
virtual void submitOutput(const SingleDerivedPath &path, const OutputName &output)=0
void addDependency(const StorePath &path)
Definition restricted-store.hh:83
virtual const StorePathSet & originalPaths()=0
virtual bool shouldModifySandbox()=0
virtual bool isAllowed(const StorePath &)=0
virtual void addDependencyImpl(const StorePath &path)=0
Definition derived-path.hh:105