Nix 2.26.3
Nix, the purely functional package manager; unstable internal interfaces
 
Loading...
Searching...
No Matches
local-overlay-store.hh
1#include "local-store.hh"
2
3namespace nix {
4
8struct LocalOverlayStoreConfig : virtual LocalStoreConfig
9{
10 LocalOverlayStoreConfig(const StringMap & params)
11 : LocalOverlayStoreConfig("local-overlay", "", params)
12 { }
13
14 LocalOverlayStoreConfig(std::string_view scheme, PathView path, const Params & params)
15 : StoreConfig(params)
16 , LocalFSStoreConfig(path, params)
17 , LocalStoreConfig(scheme, path, params)
18 {
19 }
20
21 const Setting<std::string> lowerStoreUri{(StoreConfig*) this, "", "lower-store",
22 R"(
23 [Store URL](@docroot@/command-ref/new-cli/nix3-help-stores.md#store-url-format)
24 for the lower store. The default is `auto` (i.e. use the Nix daemon or `/nix/store` directly).
25
26 Must be a store with a store dir on the file system.
27 Must be used as OverlayFS lower layer for this store's store dir.
28 )"};
29
30 const PathSetting upperLayer{(StoreConfig*) this, "", "upper-layer",
31 R"(
32 Directory containing the OverlayFS upper layer for this store's store dir.
33 )"};
34
35 Setting<bool> checkMount{(StoreConfig*) this, true, "check-mount",
36 R"(
37 Check that the overlay filesystem is correctly mounted.
38
39 Nix does not manage the overlayfs mount point itself, but the correct
40 functioning of the overlay store does depend on this mount point being set up
41 correctly. Rather than just assume this is the case, check that the lowerdir
42 and upperdir options are what we expect them to be. This check is on by
43 default, but can be disabled if needed.
44 )"};
45
46 const PathSetting remountHook{(StoreConfig*) this, "", "remount-hook",
47 R"(
48 Script or other executable to run when overlay filesystem needs remounting.
49
50 This is occasionally necessary when deleting a store path that exists in both upper and lower layers.
51 In such a situation, bypassing OverlayFS and deleting the path in the upper layer directly
52 is the only way to perform the deletion without creating a "whiteout".
53 However this causes the OverlayFS kernel data structures to get out-of-sync,
54 and can lead to 'stale file handle' errors; remounting solves the problem.
55
56 The store directory is passed as an argument to the invoked executable.
57 )"};
58
59 const std::string name() override { return "Experimental Local Overlay Store"; }
60
61 std::optional<ExperimentalFeature> experimentalFeature() const override
62 {
63 return ExperimentalFeature::LocalOverlayStore;
64 }
65
66 static std::set<std::string> uriSchemes()
67 {
68 return { "local-overlay" };
69 }
70
71 std::string doc() override;
72
73protected:
82 Path toUpperPath(const StorePath & path);
83};
84
91class LocalOverlayStore : public virtual LocalOverlayStoreConfig, public virtual LocalStore
92{
100 ref<LocalFSStore> lowerStore;
101
102public:
103 LocalOverlayStore(const Params & params)
104 : LocalOverlayStore("local-overlay", "", params)
105 {
106 }
107
108 LocalOverlayStore(std::string_view scheme, PathView path, const Params & params);
109
110 std::string getUri() override
111 {
112 return "local-overlay://";
113 }
114
115private:
120 void registerDrvOutput(const Realisation & info) override;
121
125 void queryPathInfoUncached(const StorePath & path,
126 Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept override;
127
134 bool isValidPathUncached(const StorePath & path) override;
135
139 void queryReferrers(const StorePath & path, StorePathSet & referrers) override;
140
144 StorePathSet queryValidDerivers(const StorePath & path) override;
145
149 std::optional<StorePath> queryPathFromHashPart(const std::string & hashPart) override;
150
155 void registerValidPaths(const ValidPathInfos & infos) override;
156
160 void queryRealisationUncached(const DrvOutput&,
161 Callback<std::shared_ptr<const Realisation>> callback) noexcept override;
162
166 void collectGarbage(const GCOptions & options, GCResults & results) override;
167
172 void deleteStorePath(const Path & path, uint64_t & bytesFreed) override;
173
187 void optimiseStore() override;
188
198 VerificationResult verifyAllValidPaths(RepairFlag repair) override;
199
203 void queryGCReferrers(const StorePath & path, StorePathSet & referrers) override;
204
210 void remountIfNecessary();
211
215 std::atomic_bool _remountRequired = false;
216};
217
218}
Definition callback.hh:17
std::string getUri() override
Definition local-overlay-store.hh:110
LocalStore(const Params &params)
Definition local-store.cc:354
Definition config.hh:345
Definition config.hh:320
Definition path.hh:27
Definition ref.hh:15
RepairFlag repair
Definition lexer.l:7173
Definition realisation.hh:24
Definition gc-store.hh:15
Definition gc-store.hh:60
std::optional< ExperimentalFeature > experimentalFeature() const override
Definition local-overlay-store.hh:61
std::string doc() override
Definition local-overlay-store.cc:10
const std::string name() override
Definition local-overlay-store.hh:59
Path toUpperPath(const StorePath &path)
Definition local-overlay-store.cc:17
LocalFSStoreConfig(PathView path, const Params &params)
Definition local-fs-store.cc:11
Definition realisation.hh:49
Definition store-api.hh:101
std::string Path
Definition types.hh:22