Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
local-fs-store.hh
Go to the documentation of this file.
1#pragma once
3
7
8namespace nix {
9
10struct LocalFSStoreConfig : virtual StoreConfig
11{
12private:
13 void anchor() override;
14
16 makeRootDirSetting(LocalFSStoreConfig & self, std::optional<AbsolutePath> defaultValue)
17 {
18 return {
19 &self,
20 std::move(defaultValue),
21 "root",
22 "Directory prefixed to all other paths.",
23 };
24 }
25
26public:
27 LocalFSStoreConfig(const Params & params)
28 : StoreConfig(params, FilePathType::Native)
29 {
30 }
31
39 LocalFSStoreConfig(const std::filesystem::path & path, const Params & params);
40
41 Setting<std::optional<AbsolutePath>> rootDir = makeRootDirSetting(*this, std::nullopt);
42
43 Setting<AbsolutePath> stateDir{
44 this,
45 rootDir.get() ? *rootDir.get() / "nix" / "var" / "nix" : StoreConfig::getStateDir(),
46 "state",
47 R"(
48 Directory where Nix stores state.
49
50 Defaults to [`NIX_STATE_DIR`](@docroot@/command-ref/env-common.md#env-NIX_STATE_DIR) when [`root`](#@store-slug@-root) is not set.
51 )",
52 };
53
55 this,
56 rootDir.get() ? *rootDir.get() / "nix" / "var" / "log" / "nix" : StoreConfig::getLogDir(),
57 "log",
58 R"(
59 Directory where Nix stores log files.
60
61 Defaults to [`NIX_LOG_DIR`](@docroot@/command-ref/env-common.md#env-NIX_LOG_DIR) when [`root`](#@store-slug@-root) is not set.
62 )",
63 };
64
65 Setting<AbsolutePath> realStoreDir{
66 this,
67 rootDir.get() ? *rootDir.get() / "nix" / "store" : std::filesystem::path{storeDir},
68 "real",
69 R"(
70 Physical path of the Nix store.
71
72 Defaults to [`store`](#@store-slug@-store) when [`root`](#@store-slug@-root) is not set.
73 )",
74 };
75
76 const std::filesystem::path & getStateDir() const override
77 {
78 return stateDir.get();
79 }
80
81 const std::filesystem::path & getLogDir() const override
82 {
83 return logDir.get();
84 }
85};
86
87struct alignas(8) /* Work around ASAN failures on i686-linux. */
88 LocalFSStore : virtual Store,
89 virtual GcStore,
90 virtual LogStore
91{
92private:
93 void anchor() override;
94
95public:
96 using Config = LocalFSStoreConfig;
97
98 const Config & config;
99
100 inline static std::string operationName = "Local Filesystem Store";
101
102 static const std::filesystem::path drvsLogDir;
103
104 LocalFSStore(const Config & params);
105
106 ref<SourceAccessor> getFSAccessor(bool requireValidPath = true) override;
107 std::shared_ptr<SourceAccessor> getFSAccessor(const StorePath & path, bool requireValidPath = true) override;
108
123 virtual std::filesystem::path addPermRoot(const StorePath & storePath, const std::filesystem::path & gcRoot) = 0;
124
125 virtual std::filesystem::path getRealStoreDir()
126 {
127 return config.realStoreDir;
128 }
129
130 std::filesystem::path toRealPath(const StorePath & storePath)
131 {
132 return getRealStoreDir() / storePath.to_string();
133 }
134
135 std::optional<std::string> getBuildLogExact(const StorePath & path) override;
136};
137
138} // namespace nix
Definition configuration.hh:476
Definition path.hh:33
Definition ref.hh:58
Definition gc-store.hh:118
Definition local-fs-store.hh:11
const std::filesystem::path & getStateDir() const override
Definition local-fs-store.hh:76
const std::filesystem::path & getLogDir() const override
Definition local-fs-store.hh:81
virtual std::filesystem::path addPermRoot(const StorePath &storePath, const std::filesystem::path &gcRoot)=0
ref< SourceAccessor > getFSAccessor(bool requireValidPath=true) override
Definition local-fs-store.cc:178
Definition log-store.hh:9
@ Native
Definition store-api.hh:163
virtual const std::filesystem::path & getLogDir() const
Definition store-api.cc:1301
virtual const std::filesystem::path & getStateDir() const
Definition store-api.cc:1296