Nix 2.26.3
Nix, the purely functional package manager; unstable internal interfaces
 
Loading...
Searching...
No Matches
profiles.hh File Reference
#include "types.hh"
#include "pathlocks.hh"
#include <optional>
#include <time.h>

Go to the source code of this file.

Classes

struct  nix::Generation
 

Typedefs

typedef uint64_t nix::GenerationNumber
 
typedef std::list< Generationnix::Generations
 

Functions

std::pair< Generations, std::optional< GenerationNumber > > nix::findGenerations (Path profile)
 
Path nix::createGeneration (LocalFSStore &store, Path profile, StorePath outPath)
 
void nix::deleteGeneration (const Path &profile, GenerationNumber gen)
 
void nix::deleteGenerations (const Path &profile, const std::set< GenerationNumber > &gensToDelete, bool dryRun)
 
void nix::deleteGenerationsGreaterThan (const Path &profile, GenerationNumber max, bool dryRun)
 
void nix::deleteOldGenerations (const Path &profile, bool dryRun)
 
void nix::deleteGenerationsOlderThan (const Path &profile, time_t t, bool dryRun)
 
time_t nix::parseOlderThanTimeSpec (std::string_view timeSpec)
 
void nix::switchLink (Path link, Path target)
 
void nix::switchGeneration (const Path &profile, std::optional< GenerationNumber > dstGen, bool dryRun)
 
void nix::lockProfile (PathLocks &lock, const Path &profile)
 
std::string nix::optimisticLockProfile (const Path &profile)
 
Path nix::profilesDir ()
 
Path nix::rootProfilesDir ()
 
Path nix::defaultChannelsDir ()
 
Path nix::rootChannelsDir ()
 
Path nix::getDefaultProfile ()
 

Detailed Description

Implementation of Profiles.

See the manual for additional information.

Typedef Documentation

◆ GenerationNumber

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.

◆ Generations

typedef std::list<Generation> nix::Generations

All the generations of a profile

Function Documentation

◆ createGeneration()

Path nix::createGeneration ( LocalFSStore & store,
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.

◆ defaultChannelsDir()

Path nix::defaultChannelsDir ( )

Create and return the path to the file used for storing the users's channels

◆ deleteGeneration()

void nix::deleteGeneration ( const Path & profile,
GenerationNumber gen )

Unconditionally delete a generation

Parameters
profileA profile specified by its name and location combined into a path.
genThe 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.

Todo
Should we expose this at all?

◆ deleteGenerations()

void nix::deleteGenerations ( const Path & profile,
const std::set< GenerationNumber > & gensToDelete,
bool dryRun )

Delete the given set of generations.

Parameters
profileThe profile, specified by its name and location combined into a path, whose generations we want to delete.
gensToDeleteThe generations to delete, specified by a set of numbers.
dryRunLog 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.

◆ deleteGenerationsGreaterThan()

void nix::deleteGenerationsGreaterThan ( const Path & profile,
GenerationNumber max,
bool dryRun )

Delete generations older than max passed the current generation.

Parameters
profileThe profile, specified by its name and location combined into a path, whose generations we want to delete.
maxHow many generations to keep up to the current one. Must be at least 1 so we don't delete the current one.
dryRunLog what would be deleted instead of actually doing so.

◆ deleteGenerationsOlderThan()

void nix::deleteGenerationsOlderThan ( const Path & profile,
time_t t,
bool dryRun )

Delete generations older than t, except for the most recent one older than t.

Parameters
profileThe profile, specified by its name and location combined into a path, whose generations we want to delete.
dryRunLog what would be deleted instead of actually doing so.

◆ deleteOldGenerations()

void nix::deleteOldGenerations ( const Path & profile,
bool dryRun )

Delete all generations other than the current one

Parameters
profileThe profile, specified by its name and location combined into a path, whose generations we want to delete.
dryRunLog what would be deleted instead of actually doing so.

◆ findGenerations()

std::pair< Generations, std::optional< GenerationNumber > > nix::findGenerations ( Path profile)

Find all generations for the given profile.

Parameters
profileA 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.
Returns
The pair of:
  • The list of currently present generations for the specified profile, sorted by ascending generation number.
  • The number of the current/active generation.

Note that the current/active generation need not be the latest one.

◆ getDefaultProfile()

Path nix::getDefaultProfile ( )

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

◆ lockProfile()

void nix::lockProfile ( PathLocks & lock,
const Path & profile )

Ensure exclusive access to a profile. Any command that modifies the profile first acquires this lock.

◆ optimisticLockProfile()

std::string nix::optimisticLockProfile ( const Path & profile)

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.

◆ parseOlderThanTimeSpec()

time_t nix::parseOlderThanTimeSpec ( std::string_view timeSpec)

Parse a temp spec intended for deleteGenerationsOlderThan().

Throws an exception if timeSpec fails to parse.

◆ profilesDir()

Path nix::profilesDir ( )

Create and return the path to a directory suitable for storing the user’s profiles.

◆ rootChannelsDir()

Path nix::rootChannelsDir ( )

Return the path to the channel directory for root (but don't try creating it)

◆ rootProfilesDir()

Path nix::rootProfilesDir ( )

Return the path to the profile directory for root (but don't try creating it)

◆ switchGeneration()

void nix::switchGeneration ( const 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.

◆ switchLink()

void nix::switchLink ( Path link,
Path target )

Smaller wrapper around replaceSymlink for replacing the current generation of a profile. Does not enforce proper structure.

Todo
Always use switchGeneration() instead, and delete this.