Nix
2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Toggle main menu visibility
Loading...
Searching...
No Matches
restricted-store.hh
Go to the documentation of this file.
1
#pragma once
3
4
#include "
nix/store/store-api.hh
"
5
#include "
nix/util/sync.hh
"
6
7
#include <future>
8
9
namespace
nix {
10
11
struct
Builder
;
12
class
LocalStore
;
13
struct
LocalStoreConfig
;
14
class
Worker
;
15
29
struct
RestrictionContext
30
{
31
private
:
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
36
public
:
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
{
107
if
(
shouldModifySandbox
())
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
119
protected
:
120
126
virtual
void
addDependencyImpl
(
const
StorePath
& path) = 0;
127
};
128
132
ref<Store>
makeRestrictedStore
(
ref<LocalStoreConfig>
config,
ref<LocalStore>
next,
RestrictionContext
& context);
133
138
ref<Builder>
makeRestrictedBuilder
(
Worker
& inner,
RestrictionContext
& context);
139
140
}
// namespace nix
nix::LocalStore
Definition
local-store.hh:185
nix::StorePath
Definition
path.hh:33
nix::Worker
Definition
worker.hh:110
nix::ref
Definition
ref.hh:58
nix::OutputName
std::string OutputName
Definition
outputs-spec.hh:18
nix::makeRestrictedBuilder
ref< Builder > makeRestrictedBuilder(Worker &inner, RestrictionContext &context)
Definition
restricted-store.cc:396
nix::makeRestrictedStore
ref< Store > makeRestrictedStore(ref< LocalStoreConfig > config, ref< LocalStore > next, RestrictionContext &context)
Definition
restricted-store.cc:200
store-api.hh
nix::Builder
Definition
build.hh:17
nix::DerivedPath
Definition
derived-path.hh:238
nix::DrvOutput
Definition
realisation.hh:26
nix::LocalStoreConfig
Definition
local-store.hh:85
nix::RestrictionContext::State
Definition
restricted-store.hh:43
nix::RestrictionContext::State::addedDrvOutputs
std::set< DrvOutput > addedDrvOutputs
Definition
restricted-store.hh:52
nix::RestrictionContext::State::addedPaths
std::map< StorePath, std::shared_future< void > > addedPaths
Definition
restricted-store.hh:47
nix::RestrictionContext
Definition
restricted-store.hh:30
nix::RestrictionContext::submitOutput
virtual void submitOutput(const SingleDerivedPath &path, const OutputName &output)=0
nix::RestrictionContext::addDependency
void addDependency(const StorePath &path)
Definition
restricted-store.hh:83
nix::RestrictionContext::originalPaths
virtual const StorePathSet & originalPaths()=0
nix::RestrictionContext::shouldModifySandbox
virtual bool shouldModifySandbox()=0
nix::RestrictionContext::isAllowed
virtual bool isAllowed(const StorePath &)=0
nix::RestrictionContext::addDependencyImpl
virtual void addDependencyImpl(const StorePath &path)=0
nix::SingleDerivedPath
Definition
derived-path.hh:105
sync.hh
libstore
include
nix
store
restricted-store.hh
Generated by
1.18.0