Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
local-overlay-store.hh
2
3namespace nix {
4
8struct LocalOverlayStoreConfig : virtual LocalStoreConfig
9{
10private:
11 void anchor() override;
12
13public:
14 LocalOverlayStoreConfig(const StringMap & params)
15 : LocalOverlayStoreConfig("", params)
16 {
17 }
18
19 LocalOverlayStoreConfig(const std::filesystem::path & path, const Params & params)
21 , LocalFSStoreConfig(path, params)
22 , LocalStoreConfig(path, params)
23 {
24 }
25
26 Setting<std::string> lowerStoreUri{
27 (StoreConfig *) this,
28 "",
29 "lower-store",
30 R"(
31 [Store URL](@docroot@/command-ref/new-cli/nix3-help-stores.md#store-url-format)
32 for the lower store. The default is `auto` (i.e. use the Nix daemon or `/nix/store` directly).
33
34 Must be a store with a store dir on the file system.
35 Must be used as OverlayFS lower layer for this store's store dir.
36 )"};
37
38 /* The default is a placeholder, but it must still be an absolute
39 path on the host. */
40 const Setting<AbsolutePath> upperLayer{
41 (StoreConfig *) this,
42#ifdef _WIN32
43 "C:\\"
44#else
45 "/"
46#endif
47 "upper-layer-must-be-set",
48 "upper-layer",
49 R"(
50 Directory containing the OverlayFS upper layer for this store's store dir.
51 )"};
52
53 Setting<bool> checkMount{
54 (StoreConfig *) this,
55 true,
56 "check-mount",
57 R"(
58 Check that the overlay filesystem is correctly mounted.
59
60 Nix does not manage the overlayfs mount point itself, but the correct
61 functioning of the overlay store does depend on this mount point being set up
62 correctly. Rather than just assume this is the case, check that the lowerdir
63 and upperdir options are what we expect them to be. This check is on by
64 default, but can be disabled if needed.
65 )"};
66
67 const Setting<std::optional<AbsolutePath>> remountHook{
68 (StoreConfig *) this,
69 std::nullopt,
70 "remount-hook",
71 R"(
72 Script or other executable to run when overlay filesystem needs remounting.
73
74 This is occasionally necessary when deleting a store path that exists in both upper and lower layers.
75 In such a situation, bypassing OverlayFS and deleting the path in the upper layer directly
76 is the only way to perform the deletion without creating a "whiteout".
77 However this causes the OverlayFS kernel data structures to get out-of-sync,
78 and can lead to 'stale file handle' errors; remounting solves the problem.
79
80 The store directory is passed as an argument to the invoked executable.
81 )"};
82
83 static const std::string name()
84 {
85 return "Experimental Local Overlay Store";
86 }
87
88 static std::optional<ExperimentalFeature> experimentalFeature()
89 {
90 return ExperimentalFeature::LocalOverlayStore;
91 }
92
93 static StringSet uriSchemes()
94 {
95 return {"local-overlay"};
96 }
97
98 static std::string doc();
99
100 ref<Store> openStore() const override;
101
102 StoreReference getReference() const override;
103
104protected:
113 std::filesystem::path toUpperPath(const StorePath & path) const;
114
115 friend struct LocalOverlayStore;
116};
117
124struct LocalOverlayStore : virtual LocalStore
125{
126 using Config = LocalOverlayStoreConfig;
127
128 ref<const Config> config;
129
130 LocalOverlayStore(ref<const Config>);
131
132private:
133 void anchor() override;
134
142 ref<LocalFSStore> lowerStore;
143
148 void registerDrvOutputUnchecked(const Realisation & info) override;
149
153 void queryPathInfoUncached(
154 const StorePath & path, Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept override;
155
162 bool isValidPathUncached(const StorePath & path) override;
163
167 void queryReferrers(const StorePath & path, StorePathSet & referrers) override;
168
172 StorePathSet queryValidDerivers(const StorePath & path) override;
173
177 std::optional<StorePath> queryPathFromHashPart(const std::string & hashPart) override;
178
183 void registerValidPaths(const ValidPathInfos & infos) override;
184
188 void queryRealisationUncached(
189 const DrvOutput &, Callback<std::shared_ptr<const UnkeyedRealisation>> callback) noexcept override;
190
194 void collectGarbage(const GCOptions & options, GCResults & results) override;
195
200 void deleteStorePath(const std::filesystem::path & path, uint64_t & bytesFreed, bool isKnownPath) override;
201
215 void optimiseStore() override;
216
226 VerificationResult verifyAllValidPaths(RepairFlag repair) override;
227
231 void queryGCReferrers(const StorePath & path, StorePathSet & referrers) override;
232
238 void remountIfNecessary();
239
243 std::atomic_bool _remountRequired = false;
244};
245
246} // namespace nix
Definition callback.hh:19
LocalStore(ref< const Config > params)
Definition local-store.cc:126
Definition configuration.hh:476
Definition path.hh:33
Definition ref.hh:58
Definition realisation.hh:26
Definition gc-store.hh:38
Definition gc-store.hh:78
Definition local-fs-store.hh:11
Definition local-overlay-store.hh:9
ref< Store > openStore() const override
Definition local-overlay-store.cc:24
StoreReference getReference() const override
Definition local-overlay-store.cc:30
std::filesystem::path toUpperPath(const StorePath &path) const
Definition local-overlay-store.cc:40
Definition local-store.hh:416
Definition realisation.hh:103
@ Native
Definition store-api.hh:163
Definition store-api.hh:240
std::map< std::string, std::string, std::less<> > StringMap
Definition types.hh:26
std::set< std::string, std::less<> > StringSet
Definition types.hh:45