![]() |
Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
|
#include <filesystem>#include <optional>#include <time.h>#include "nix/util/types.hh"#include "nix/store/pathlocks.hh"Go to the source code of this file.
Classes | |
| struct | nix::Generation |
Typedefs | |
| typedef uint64_t | nix::GenerationNumber |
| typedef std::list< Generation > | nix::Generations |
Functions | |
| std::pair< Generations, std::optional< GenerationNumber > > | nix::findGenerations (std::filesystem::path profile) |
| std::filesystem::path | nix::createGeneration (LocalFSStore &store, std::filesystem::path profile, StorePath outPath) |
| void | nix::deleteGeneration (const std::filesystem::path &profile, GenerationNumber gen) |
| void | nix::deleteGenerations (const std::filesystem::path &profile, const std::set< GenerationNumber > &gensToDelete, bool dryRun) |
| void | nix::deleteGenerationsGreaterThan (const std::filesystem::path &profile, GenerationNumber max, bool dryRun) |
| void | nix::deleteOldGenerations (const std::filesystem::path &profile, bool dryRun) |
| void | nix::deleteGenerationsOlderThan (const std::filesystem::path &profile, time_t t, bool dryRun) |
| time_t | nix::parseOlderThanTimeSpec (std::string_view timeSpec) |
| void | nix::switchLink (std::filesystem::path link, std::filesystem::path target) |
| void | nix::switchGeneration (const std::filesystem::path &profile, std::optional< GenerationNumber > dstGen, bool dryRun) |
| void | nix::lockProfile (PathLocks &lock, const std::filesystem::path &profile) |
| std::filesystem::path | nix::profilesDir (ProfileDirsOptions opts) |
| std::filesystem::path | nix::rootProfilesDir (ProfileDirsOptions opts) |
| std::filesystem::path | nix::defaultChannelsDir (ProfileDirsOptions opts) |
| std::filesystem::path | nix::rootChannelsDir (ProfileDirsOptions opts) |
| std::filesystem::path | nix::getDefaultProfile (ProfileDirsOptions opts) |
Implementation of Profiles.
See the manual for additional information.
| typedef uint64_t nix::GenerationNumber |
A positive number identifying a generation for a given profile.
Generation numbers are assigned sequentially. Each new generation is assigned 1 + the current highest generation number.
| typedef std::list<Generation> nix::Generations |
All the generations of a profile
| std::filesystem::path nix::createGeneration | ( | LocalFSStore & | store, |
| std::filesystem::path | profile, | ||
| StorePath | outPath ) |
Create a new generation of the given profile
If the previous generation (not the currently active one!) has a distinct store object, a fresh generation number is mapped to the given store object, referenced by path. Otherwise, the previous generation is assumed.
The behavior of reusing existing generations like this makes this procedure idempotent. It also avoids clutter.
| std::filesystem::path nix::defaultChannelsDir | ( | ProfileDirsOptions | opts | ) |
Create and return the path to the file used for storing the users's channels
| void nix::deleteGeneration | ( | const std::filesystem::path & | profile, |
| GenerationNumber | gen ) |
Unconditionally delete a generation
| profile | A profile specified by its name and location combined into a path. |
| gen | The generation number specifying exactly which generation to delete. |
Because there is no check of whether the generation to delete is active, this is somewhat unsafe.
| void nix::deleteGenerations | ( | const std::filesystem::path & | profile, |
| const std::set< GenerationNumber > & | gensToDelete, | ||
| bool | dryRun ) |
Delete the given set of generations.
| profile | The profile, specified by its name and location combined into a path, whose generations we want to delete. |
| gensToDelete | The generations to delete, specified by a set of numbers. |
| dryRun | Log what would be deleted instead of actually doing so. |
Trying to delete the currently active generation will fail, and cause no generations to be deleted.
| void nix::deleteGenerationsGreaterThan | ( | const std::filesystem::path & | profile, |
| GenerationNumber | max, | ||
| bool | dryRun ) |
Delete generations older than max passed the current generation.
| profile | The profile, specified by its name and location combined into a path, whose generations we want to delete. |
| max | How many generations to keep up to the current one. Must be at least 1 so we don't delete the current one. |
| dryRun | Log what would be deleted instead of actually doing so. |
| void nix::deleteGenerationsOlderThan | ( | const std::filesystem::path & | profile, |
| time_t | t, | ||
| bool | dryRun ) |
Delete generations older than t, except for the most recent one older than t.
| profile | The profile, specified by its name and location combined into a path, whose generations we want to delete. |
| dryRun | Log what would be deleted instead of actually doing so. |
| void nix::deleteOldGenerations | ( | const std::filesystem::path & | profile, |
| bool | dryRun ) |
Delete all generations other than the current one
| profile | The profile, specified by its name and location combined into a path, whose generations we want to delete. |
| dryRun | Log what would be deleted instead of actually doing so. |
| std::pair< Generations, std::optional< GenerationNumber > > nix::findGenerations | ( | std::filesystem::path | profile | ) |
Find all generations for the given profile.
| profile | A profile specified by its name and location combined into a path. E.g. if "foo" is the name of the profile, and "/bar/baz" is the directory it is in, then the path "/bar/baz/foo" would be the argument for this parameter. |
Note that the current/active generation need not be the latest one.
| std::filesystem::path nix::getDefaultProfile | ( | ProfileDirsOptions | opts | ) |
Resolve the default profile (~/.nix-profile by default, $XDG_STATE_HOME/nix/profile if XDG Base Directory Support is enabled), and create if doesn't exist
| void nix::lockProfile | ( | PathLocks & | lock, |
| const std::filesystem::path & | profile ) |
Ensure exclusive access to a profile. Any command that modifies the profile first acquires this lock.
| time_t nix::parseOlderThanTimeSpec | ( | std::string_view | timeSpec | ) |
Parse a temp spec intended for deleteGenerationsOlderThan().
Throws an exception if timeSpec fails to parse.
| std::filesystem::path nix::profilesDir | ( | ProfileDirsOptions | opts | ) |
Optimistic locking is used by long-running operations like `nix-env -i'. Instead of acquiring the exclusive lock for the entire duration of the operation, we just perform the operation optimistically (without an exclusive lock), and check at the end whether the profile changed while we were busy (i.e., the symlink target changed). If so, the operation is restarted. Restarting is generally cheap, since the build results are still in the Nix store. Most of the time, only the user environment has to be rebuilt. */ std::string optimisticLockProfile(const std::filesystem::path & profile);
struct ProfileDirsOptions { const std::filesystem::path & nixStateDir; bool useXDGBaseDirectories; };
/** Create and return the path to a directory suitable for storing the user’s profiles.
| std::filesystem::path nix::rootChannelsDir | ( | ProfileDirsOptions | opts | ) |
Return the path to the channel directory for root (but don't try creating it)
| std::filesystem::path nix::rootProfilesDir | ( | ProfileDirsOptions | opts | ) |
Return the path to the profile directory for root (but don't try creating it)
| void nix::switchGeneration | ( | const std::filesystem::path & | profile, |
| std::optional< GenerationNumber > | dstGen, | ||
| bool | dryRun ) |
Roll back a profile to the specified generation, or to the most recent one older than the current.
| void nix::switchLink | ( | std::filesystem::path | link, |
| std::filesystem::path | target ) |
Smaller wrapper around replaceSymlink for replacing the current generation of a profile. Does not enforce proper structure.