15#include <unordered_map>
19#include <nix/config.hh>
20#include <nix/globals.hh>
35namespace flox::resolver {
36struct ManifestDescriptor;
46namespace flox::resolver {
51template<manifest_raw_type RawType>
55 if ( ! std::filesystem::exists( manifestPath ) )
58 + manifestPath.string() );
77template<manifest_raw_type RawType>
91 template<manifest_raw_type _RawType = RawType>
92 typename std::enable_if<std::derived_from<_RawType, GlobalManifestRaw>,
96 if ( this->manifestRaw.registry.has_value() )
98 this->registryRaw = *this->manifestRaw.registry;
103 template<manifest_raw_type _RawType = RawType>
104 typename std::enable_if<std::derived_from<_RawType, GlobalManifestRawGA>,
114 using rawType = RawType;
122 this->manifestRaw.check();
126 explicit ManifestBase( RawType raw ) : manifestRaw( std::move( raw ) )
128 this->manifestRaw.check();
132 explicit ManifestBase(
const std::filesystem::path & manifestPath )
133 : manifestRaw( readManifestFromPath<RawType>( manifestPath ) )
135 this->manifestRaw.check();
140 operator=(
const ManifestBase & )
144 operator=( ManifestBase && ) noexcept
147 [[nodiscard]] const RawType &
148 getManifestRaw()
const
150 return this->manifestRaw;
153 [[nodiscard]]
const RegistryRaw &
154 getRegistryRaw()
const
156 return this->registryRaw;
161 [[nodiscard]] RegistryRaw
162 getLockedRegistry(
const nix::ref<nix::Store> & store
163 = NixStoreMixin().getStore() )
const
169 [[nodiscard]] std::vector<System>
172 const auto & manifest = this->getManifestRaw();
173 if ( manifest.options.has_value() && manifest.options->systems.has_value() )
175 return *manifest.options->systems;
177 return std::vector<System> { nix::settings.thisSystem.get() };
180 [[nodiscard]] pkgdb::PkgQueryArgs
181 getBaseQueryArgs()
const
183 pkgdb::PkgQueryArgs args;
184 if ( ! this->manifestRaw.options.has_value() ) {
return args; }
186 if ( this->manifestRaw.options->systems.has_value() )
188 args.systems = *this->manifestRaw.options->systems;
191 if ( this->manifestRaw.options->allow.has_value() )
193 if ( this->manifestRaw.options->allow->unfree.has_value() )
195 args.allowUnfree = *this->manifestRaw.options->allow->unfree;
197 if ( this->manifestRaw.options->allow->broken.has_value() )
199 args.allowBroken = *this->manifestRaw.options->allow->broken;
201 args.licenses = this->manifestRaw.options->allow->licenses;
204 if ( this->manifestRaw.options->semver.has_value()
205 && this->manifestRaw.options->semver->preferPreReleases.has_value() )
207 args.preferPreReleases
208 = *this->manifestRaw.options->semver->preferPreReleases;
219template<manifest_raw_type RawType>
266[[nodiscard]] std::vector<InstallDescriptors>
274template<manifest_raw_type RawType>
299 const auto & raw = this->getManifestRaw();
301 std::optional<std::vector<std::string>> maybeSystems;
302 if (
auto maybeOpts = raw.options; maybeOpts.has_value() )
304 maybeSystems = maybeOpts->systems;
307 for (
const auto & [iid, desc] : this->descriptors )
309 if ( ! desc.systems.has_value() ) {
continue; }
310 if ( ! maybeSystems.has_value() )
313 "descriptor `install." + iid
314 +
"' specifies `systems' but no `options.systems' are specified"
315 " in the manifest." );
317 for (
const auto & system : *desc.systems )
319 if ( std::find( maybeSystems->begin(), maybeSystems->end(), system )
320 == maybeSystems->end() )
322 std::stringstream msg;
323 msg <<
"descriptor `install." << iid <<
"' specifies system `"
325 <<
"' which is not in `options.systems' in the manifest.";
336 if ( ! this->manifestRaw.install.has_value() ) {
return; }
337 for (
const auto & [iid, raw] : *this->manifestRaw.install )
340 if ( raw.has_value() )
348 this->descriptors.emplace( iid, std::move( manDesc ) );
368 explicit EnvironmentManifestBase(
const std::filesystem::path & manifestPath )
369 : ManifestBase<RawType>( readManifestFromPath<RawType>( manifestPath ) )
374 EnvironmentManifestBase &
375 operator=(
const EnvironmentManifestBase & )
378 EnvironmentManifestBase &
379 operator=( EnvironmentManifestBase && )
383 [[nodiscard]]
const InstallDescriptors &
394 [[nodiscard]] std::vector<InstallDescriptors>
406using EnvironmentManifest = EnvironmentManifestBase<ManifestRaw>;
407using EnvironmentManifestGA = EnvironmentManifestBase<ManifestRawGA>;
Description of an environment in its unlocked form.
Definition: manifest.hh:276
InstallDescriptors descriptors
Definition: manifest.hh:284
std::vector< InstallDescriptors > getGroupedDescriptors() const
Returns all descriptors, grouping those with a group field, and returning those without a group field...
Definition: manifest.hh:395
void initDescriptors()
Initialize descriptors from manifestRaw.
Definition: manifest.hh:334
void check() const
Assert the validity of the manifest, throwing an exception if it contains invalid fields.
Definition: manifest.hh:297
const InstallDescriptors & getDescriptors() const
Get descriptors from the manifest's ‘install’ field.
Definition: manifest.hh:384
Definition: manifest.hh:221
An exception thrown when a manifest file is invalid.
A global manifest containing only registry and options fields.
Definition: manifest.hh:79
std::vector< System > getSystems() const
Get the list of systems requested by the manifest.
Definition: manifest.hh:170
std::enable_if< std::derived_from< _RawType, GlobalManifestRawGA >, void >::type initRegistry()
Initialize registryRaw from manifestRaw.
Definition: manifest.hh:106
std::enable_if< std::derived_from< _RawType, GlobalManifestRaw >, void >::type initRegistry()
Initialize registryRaw from manifestRaw.
Definition: manifest.hh:94
Provides backports of some concepts features that are missing in Clang v11.
An abstract description of an environment in its unresolved state. This representation is intended fo...
std::vector< InstallDescriptors > getGroupedDescriptors(const InstallDescriptors &descriptors)
Returns all descriptors, grouping those with a group field, and returning those without a group field...
Definition: manifest.cc:35
static RawType readManifestFromPath(const std::filesystem::path &manifestPath)
Read a flox::resolver::ManifestBase from a file.
Definition: manifest.hh:53
std::unordered_map< InstallID, ManifestDescriptor > InstallDescriptors
A map of install IDs to manifest descriptors.
Definition: manifest.hh:259
RegistryRaw lockRegistry(const RegistryRaw &unlocked, const nix::ref< nix::Store > &store)
Lock an unlocked registry.
Definition: registry.cc:365
RegistryRaw getGARegistry()
Get a hard coded registry for use with flox's GA release.
Definition: registry.cc:377
nlohmann::json readAndCoerceJSON(const std::filesystem::path &path)
Read a file and coerce its contents to JSON based on its extension.
Definition: util.cc:102
Manages a nix runtime state blob with associated helpers.
Interfaces for constructing complex ‘Packages’ queries.
A set of user inputs used to set input preferences during search and resolution.
A set of user inputs used to set input preferences during search and resolution.
Definition: registry.hh:297
A set of user defined requirements describing a package/dependency.
Definition: descriptor.hh:221
std::optional< std::string > name
Definition: descriptor.hh:226
Miscellaneous typedefs and aliases.