Flox Package Database 1
CRUD Operations on Nix Package Metadata
Loading...
Searching...
No Matches
nix-state.hh
Go to the documentation of this file.
1/* ========================================================================== *
2 *
3 * @file flox/core/nix-state.hh
4 *
5 * @brief Manages a `nix` runtime state blob with associated helpers.
6 *
7 *
8 * -------------------------------------------------------------------------- */
9
10#pragma once
11
12#include <memory>
13
14#include <nix/eval.hh>
15#include <nix/ref.hh>
16#include <nix/repair-flag.hh>
17#include <nix/search-path.hh>
18#include <nix/store-api.hh>
19
20
21/* -------------------------------------------------------------------------- */
22
23/* Forward Declarations. */
24
25namespace nix {
26class Logger;
27}
28
29
30/* -------------------------------------------------------------------------- */
31
32namespace flox {
33
34/* -------------------------------------------------------------------------- */
35
37nix::Logger *
38makeFilteredLogger( bool printBuildLogs );
39
40
41/* -------------------------------------------------------------------------- */
42
51void
52initNix();
53
54
55/* -------------------------------------------------------------------------- */
56
59{
60
61private:
62
63 std::shared_ptr<nix::Store> store;
66public:
67
68 /* Copy/Move base class boilerplate */
69 NixStoreMixin( const NixStoreMixin & ) = default;
70 NixStoreMixin( NixStoreMixin && ) = default;
71
72 virtual ~NixStoreMixin() = default;
73
75 operator=( const NixStoreMixin & )
76 = default;
78 operator=( NixStoreMixin && )
79 = default;
80
81
88 explicit NixStoreMixin( const nix::ref<nix::Store> & store )
89 : store( static_cast<std::shared_ptr<nix::Store>>( store ) )
90 {
91 initNix();
92 }
93
98
99
105 nix::ref<nix::Store>
107 {
108 if ( this->store == nullptr ) { this->store = nix::openStore(); }
109 return static_cast<nix::ref<nix::Store>>( this->store );
110 }
111
112
113}; /* End class `NixStoreMixin' */
114
115
116/* -------------------------------------------------------------------------- */
117
123{
124
125private:
126
127 /* From `NixStoreMixin':
128 * std::shared_ptr<nix::Store> store
129 */
130
131 std::shared_ptr<nix::EvalState> state;
134public:
135
137 NixState() = default;
138
145 explicit NixState( nix::ref<nix::Store> & store ) : NixStoreMixin( store ) {}
146
147
153 nix::ref<nix::EvalState>
155 {
156 if ( this->state == nullptr )
157 {
158 this->state = std::make_shared<nix::EvalState>( nix::SearchPath(),
159 this->getStore(),
160 this->getStore() );
161 this->state->repair = nix::NoRepair;
162 }
163 return static_cast<nix::ref<nix::EvalState>>( this->state );
164 }
165
166
167}; /* End class `NixState' */
168
169
170/* -------------------------------------------------------------------------- */
171
172} // namespace flox
173
174
175/* -------------------------------------------------------------------------- *
176 *
177 *
178 *
179 * ========================================================================== */
Runtime state containing a nix store connection and a nix evaluator.
Definition: nix-state.hh:123
NixState()=default
Construct NixState using the systems default nix store.
nix::ref< nix::EvalState > getState()
Lazily open a nix evaluator.
Definition: nix-state.hh:154
NixState(nix::ref< nix::Store > &store)
Construct NixState from an existing store connection.
Definition: nix-state.hh:145
std::shared_ptr< nix::EvalState > state
Definition: nix-state.hh:131
Mixin which provides a lazy handle to a nix store connection.
Definition: nix-state.hh:59
NixStoreMixin(const nix::ref< nix::Store > &store)
Construct NixStoreMixin from an existing store connection.
Definition: nix-state.hh:88
NixStoreMixin()
Construct NixStoreMixin using the systems default nix store.
Definition: nix-state.hh:97
std::shared_ptr< nix::Store > store
Definition: nix-state.hh:63
nix::ref< nix::Store > getStore()
Lazily open a nix store connection.
Definition: nix-state.hh:106
Interfaces for use by flox.
Definition: command.cc:29
nix::Logger * makeFilteredLogger(bool printBuildLogs)
Create a custom nix::Logger which ignores some messages.
Definition: logger.cc:229
void initNix()
Perform one time nix global runtime setup.
Definition: nix-state.cc:30