1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-26 04:00:59 +01:00

in the middle of adding nixStoreState ...

This commit is contained in:
Wouter den Breejen 2007-05-18 19:50:58 +00:00
parent 4c63f18dcc
commit 8a7874d77d
11 changed files with 138 additions and 22 deletions

View file

@ -21,6 +21,8 @@ $stateDir = "@localstatedir@/nix" unless defined $stateDir;
my $storeDir = $ENV{"NIX_STORE_DIR"}; my $storeDir = $ENV{"NIX_STORE_DIR"};
$storeDir = "@storedir@" unless defined $storeDir; $storeDir = "@storedir@" unless defined $storeDir;
my $storeStateDir = $ENV{"NIX_STORE_STATE_DIR"};
$storeStateDir = "@storestatedir@" unless defined $storeStateDir;
# Prevent access problems in shared-stored installations. # Prevent access problems in shared-stored installations.
umask 0022; umask 0022;

View file

@ -396,6 +396,7 @@ static Expr prim_derivationStrict(EvalState & state, const ATermVector & args)
bool disableState = false; bool disableState = false;
string shareState = "none"; string shareState = "none";
string syncState = "all"; string syncState = "all";
string stateIndentifier = "";
for (ATermMap::const_iterator i = attrs.begin(); i != attrs.end(); ++i) { for (ATermMap::const_iterator i = attrs.begin(); i != attrs.end(); ++i) {
string key = aterm2String(i->key); string key = aterm2String(i->key);
@ -427,22 +428,13 @@ static Expr prim_derivationStrict(EvalState & state, const ATermVector & args)
else if(key == "stateDirs") { else if(key == "stateDirs") {
enableState = true; enableState = true;
value = evalExpr(state, value); value = evalExpr(state, value);
ATermList list = evalList(state, value); ATermList list = evalList(state, value);
printMsg(lvlError, format("DIRS `%1%'") % value);
printMsg(lvlError, format("DIRS `%1%'") % list);
for (ATermIterator j(list); j; ++j){ for (ATermIterator j(list); j; ++j){
Expr v = evalExpr(state, *j); Expr v = evalExpr(state, *j);
printMsg(lvlError, format("DIRS2 `%1%'") % v);
ATermMap stateDirattrs; ATermMap stateDirattrs;
queryAllAttrs(evalExpr(state, v), stateDirattrs, true); queryAllAttrs(evalExpr(state, v), stateDirattrs, true);
DerivationStateOutputDir dir = DerivationStateOutputDir(); DerivationStateOutputDir dir = DerivationStateOutputDir();
for (ATermMap::const_iterator k = stateDirattrs.begin(); k != stateDirattrs.end(); ++k) { for (ATermMap::const_iterator k = stateDirattrs.begin(); k != stateDirattrs.end(); ++k) {
@ -455,7 +447,7 @@ static Expr prim_derivationStrict(EvalState & state, const ATermVector & args)
startNest(nest, lvlVomit, format("processing statedir attribute `%1%'") % statekey); startNest(nest, lvlVomit, format("processing statedir attribute `%1%'") % statekey);
try { try {
string s = coerceToString(state, statevalue, context, true); string s = coerceToString(state, statevalue, context, true);
printMsg(lvlError, format("DIRS4 `%1%'") % s);
if (statekey == "dir") { dir.path = s; } if (statekey == "dir") { dir.path = s; }
else if (statekey == "type") { dir.type = s; } else if (statekey == "type") { dir.type = s; }
else if (statekey == "interval") { dir.interval = s; } else if (statekey == "interval") { dir.interval = s; }
@ -469,16 +461,15 @@ static Expr prim_derivationStrict(EvalState & state, const ATermVector & args)
} }
drv.stateOutputDirs[dir.path] = dir; drv.stateOutputDirs[dir.path] = dir;
//Expr e = queryAttr(v, "dir"); //Expr e = queryAttr(v, "dir");
//printMsg(lvlError, format("DIRS3 `%1%'") % e); //printMsg(lvlError, format("DIRS3 `%1%'") % e);
} }
} }
else if(key == "shareState") { string s = coerceToString(state, value, context, true); shareState = s; } else if(key == "shareState") { string s = coerceToString(state, value, context, true); shareState = s; }
else if(key == "synchronization") { string s = coerceToString(state, value, context, true); syncState = s; } else if(key == "synchronization") { string s = coerceToString(state, value, context, true); syncState = s; }
else if(key == "enableState") { bool b = evalBool(state, value); disableState = true; } else if(key == "enableState") { bool b = evalBool(state, value); disableState = true; }
else if(key == "indentifier"){ string s = coerceToString(state, value, context, true); stateIndentifier = s; }
/* All other attributes are passed to the builder through /* All other attributes are passed to the builder through
the environment. */ the environment. */
@ -570,12 +561,19 @@ static Expr prim_derivationStrict(EvalState & state, const ATermVector & args)
drv.outputs["out"] = DerivationOutput(outPath, outputHashAlgo, outputHash); drv.outputs["out"] = DerivationOutput(outPath, outputHashAlgo, outputHash);
/* Add the state path based on the outPath */ /* Add the state path based on the outPath */
//hash h = .... string callingUser = "wouterdb"; //TODO: Change into variable
drv.env["statepath"] = outPath; string statePrefix = "/nix/state/"; //TODO: Change into variable
//Path outPath = makeStatePath("stateOutput:statepath", hashDerivationModulo(state, drv), drvName);
string componentHash = printHash(hashDerivationModulo(state, drv));
Hash hash = hashString(htSHA256, stateIndentifier + callingUser + componentHash); //calculate state hash
string statePath = statePrefix + printHash(hash) + "/"; //make the state path
drv.env["statepath"] = statePath;
string enableStateS = "false"; string enableStateS = "false";
if(enableState && disableState == false) if(enableState && disableState == false)
enableStateS = "true"; enableStateS = "true";
drv.stateOutputs["stateOptions"] = DerivationStateOutput(outPath, outputHashAlgo, outputHash, enableStateS, shareState, syncState); drv.stateOutputs["state"] = DerivationStateOutput(statePath, outputHashAlgo, outputHash, enableStateS, shareState, syncState);
/* Write the resulting term into the Nix store directory. */ /* Write the resulting term into the Nix store directory. */
Path drvPath = writeDerivation(drv, drvName); Path drvPath = writeDerivation(drv, drvName);

View file

@ -87,9 +87,10 @@ static void initAndRun(int argc, char * * argv)
{ {
/* Setup Nix paths. */ /* Setup Nix paths. */
nixStore = canonPath(getEnv("NIX_STORE_DIR", getEnv("NIX_STORE", NIX_STORE_DIR))); nixStore = canonPath(getEnv("NIX_STORE_DIR", getEnv("NIX_STORE", NIX_STORE_DIR)));
nixStoreState = canonPath(getEnv("NIX_STORE_STATE_DIR", NIX_STORE_STATE_DIR)); //store state dir usually /nix/state
nixDataDir = canonPath(getEnv("NIX_DATA_DIR", NIX_DATA_DIR)); nixDataDir = canonPath(getEnv("NIX_DATA_DIR", NIX_DATA_DIR));
nixLogDir = canonPath(getEnv("NIX_LOG_DIR", NIX_LOG_DIR)); nixLogDir = canonPath(getEnv("NIX_LOG_DIR", NIX_LOG_DIR));
nixStateDir = canonPath(getEnv("NIX_STATE_DIR", NIX_STATE_DIR)); nixStateDir = canonPath(getEnv("NIX_STATE_DIR", NIX_STATE_DIR)); //nix global state dir
nixDBPath = getEnv("NIX_DB_DIR", nixStateDir + "/db"); nixDBPath = getEnv("NIX_DB_DIR", nixStateDir + "/db");
nixConfDir = canonPath(getEnv("NIX_CONF_DIR", NIX_CONF_DIR)); nixConfDir = canonPath(getEnv("NIX_CONF_DIR", NIX_CONF_DIR));
nixLibexecDir = canonPath(getEnv("NIX_LIBEXEC_DIR", NIX_LIBEXEC_DIR)); nixLibexecDir = canonPath(getEnv("NIX_LIBEXEC_DIR", NIX_LIBEXEC_DIR));

View file

@ -588,6 +588,9 @@ private:
/* The temporary directory. */ /* The temporary directory. */
Path tmpDir; Path tmpDir;
/* The state directory. */
Path stateDir;
/* File descriptor for the log file. */ /* File descriptor for the log file. */
AutoCloseFD fdLogFile; AutoCloseFD fdLogFile;
@ -759,7 +762,7 @@ void DerivationGoal::haveDerivation()
assert(store->isValidPath(drvPath)); assert(store->isValidPath(drvPath));
/* Get the derivation. */ /* Get the derivation. */
drv = derivationFromPath(drvPath); drv = derivationFromPath(drvPath); //wouter look here
for (DerivationOutputs::iterator i = drv.outputs.begin(); for (DerivationOutputs::iterator i = drv.outputs.begin();
i != drv.outputs.end(); ++i) i != drv.outputs.end(); ++i)
@ -1370,6 +1373,11 @@ void DerivationGoal::startBuilder()
/* Create a temporary directory where the build will take /* Create a temporary directory where the build will take
place. */ place. */
tmpDir = createTempDir(); tmpDir = createTempDir();
/* Create the state directory where the component can store it's state files place */
stateDir = createStateDirs(drv.stateOutputDirs, drv.stateOutputs);
//TODO create the startupscript
/* For convenience, set an environment pointing to the top build /* For convenience, set an environment pointing to the top build
directory. */ directory. */

View file

@ -82,6 +82,34 @@ Derivation parseDerivation(ATerm t)
out.hash = aterm2String(hash); out.hash = aterm2String(hash);
drv.outputs[aterm2String(id)] = out; drv.outputs[aterm2String(id)] = out;
} }
//parse state part
for (ATermIterator i(stateOuts); i; ++i) {
ATerm id, statepath, hashAlgo, hash, enabled, shared, synchronization;
if (!matchDerivationStateOutput(*i, id, statepath, hashAlgo, hash, enabled, shared, synchronization))
throwBadDrv(t);
DerivationStateOutput stateOut;
stateOut.statepath = aterm2String(statepath);
//checkPath(stateOut.path); //should we check the statpath .... ???
stateOut.hashAlgo = aterm2String(hashAlgo);
stateOut.hash = aterm2String(hash);
stateOut.enabled = aterm2String(enabled);
stateOut.shared = aterm2String(shared);
stateOut.synchronization = aterm2String(synchronization);
drv.stateOutputs[aterm2String(id)] = stateOut;
}
//parse state dirs part
for (ATermIterator i(stateOutDirs); i; ++i) {
ATerm id, path, type, interval;
if (!matchDerivationStateOutputDir(*i, id, path, type, interval))
throwBadDrv(t);
DerivationStateOutputDir stateOutDirs;
stateOutDirs.path = aterm2String(path);
stateOutDirs.type = aterm2String(type);
stateOutDirs.interval = aterm2String(interval);
drv.stateOutputDirs[aterm2String(id)] = stateOutDirs;
}
for (ATermIterator i(inDrvs); i; ++i) { for (ATermIterator i(inDrvs); i; ++i) {
ATerm drvPath; ATerm drvPath;

View file

@ -69,6 +69,12 @@ struct DerivationStateOutputDir
this->type = type; this->type = type;
this->interval = interval; this->interval = interval;
} }
//sort function
/*bool operator<(const DerivationStateOutputDir& a, const DerivationStateOutputDir& b) {
return a.path < b.path;
} */
bool operator<(const DerivationStateOutputDir& a) const { return path < a.path; }
}; };

View file

@ -9,6 +9,7 @@ namespace nix {
string nixStore = "/UNINIT"; string nixStore = "/UNINIT";
string nixStoreState = "/UNINIT";
string nixDataDir = "/UNINIT"; string nixDataDir = "/UNINIT";
string nixLogDir = "/UNINIT"; string nixLogDir = "/UNINIT";
string nixStateDir = "/UNINIT"; string nixStateDir = "/UNINIT";

View file

@ -18,8 +18,8 @@ extern string nixDataDir; /* !!! fix */
/* nixLogDir is the directory where we log various operations. */ /* nixLogDir is the directory where we log various operations. */
extern string nixLogDir; extern string nixLogDir;
/* nixStateDir is the directory where state is stored. */ /* nixStateDir is the directory where the state dirs of the components are stored. */
extern string nixStateDir; extern string nixStoreState;
/* nixDBPath is the path name of our Berkeley DB environment. */ /* nixDBPath is the path name of our Berkeley DB environment. */
extern string nixDBPath; extern string nixDBPath;

View file

@ -66,8 +66,7 @@ void checkStoreName(const string & name)
} }
Path makeStorePath(const string & type, Path makeStorePath(const string & type, const Hash & hash, const string & suffix)
const Hash & hash, const string & suffix)
{ {
/* e.g., "source:sha256:1abc...:/nix/store:foo.tar.gz" */ /* e.g., "source:sha256:1abc...:/nix/store:foo.tar.gz" */
string s = type + ":sha256:" + printHash(hash) + ":" string s = type + ":sha256:" + printHash(hash) + ":"
@ -80,6 +79,20 @@ Path makeStorePath(const string & type,
+ "-" + suffix; + "-" + suffix;
} }
Path makeStatePath(const string & type, const Hash & hash, const string & suffix)
{
/* e.g., "source:sha256:1abc...:/nix/store:foo.tar.gz" */
string s = type + ":sha256:" + printHash(hash) + ":"
+ nixStoreState + ":" + suffix;
checkStoreName(suffix);
return nixStoreState + "/"
+ printHash32(compressHash(hashString(htSHA256, s), 20))
+ "-" + suffix;
}
Path makeFixedOutputPath(bool recursive, Path makeFixedOutputPath(bool recursive,
string hashAlgo, Hash hash, string name) string hashAlgo, Hash hash, string name)

View file

@ -15,7 +15,7 @@
#include <fcntl.h> #include <fcntl.h>
#include "util.hh" #include "util.hh"
#include "../libstore/derivations.hh"
extern char * * environ; extern char * * environ;
@ -348,6 +348,61 @@ Path createTempDir(const Path & tmpRoot)
} }
} }
//TODO include rights, variable svn ... ?
Path createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const DerivationStateOutputs & stateOutputs)
{
/*while (1) {
checkInterrupt();
if (mkdir(statePath.c_str(), 0777) == 0) {
if (chown(statePath.c_str(), (uid_t) -1, getegid()) != 0)
throw SysError(format("setting group of state directory `%1%'") % statePath);
return tmpDir;
}
if (errno != EEXIST)
throw SysError(format("creating state directory `%1%'") % statePath);
}*/
string stateDir = stateOutputs.find("state")->second.statepath;
//Convert the map into a sortable vector
vector<DerivationStateOutputDir> stateDirsVector;
for (DerivationStateOutputDirs::const_reverse_iterator i = stateOutputDirs.rbegin(); i != stateOutputDirs.rend(); ++i){
stateDirsVector.push_back(i->second);
}
sort(stateDirsVector.begin(), stateDirsVector.end());
for (vector<DerivationStateOutputDir>::iterator i = stateDirsVector.begin(); i != stateDirsVector.end(); ++i)
{
DerivationStateOutputDir d = *(i);
printMsg(lvlError, format("test `%1%'") % d.path);
//calc create repos for this state location
Hash hash = hashString(htSHA256, stateDir + d.path);
/*
cd ...
svnadmin create hashcode
//create dirs
svn checkout file:///nix/state/XXXX/PATH_TO_REPOS dir
chmod ....
chmod ....
//create commit script
svn add *
svn revert file-that-I-do-not-want-added another-file-not-to-add
*/
}
//create super commit script
//return root path
Path tmpDir;
return tmpDir;
}
void createDirs(const Path & path) void createDirs(const Path & path)
{ {

View file

@ -2,6 +2,7 @@
#define __UTIL_H #define __UTIL_H
#include "types.hh" #include "types.hh"
#include "../libstore/derivations.hh"
#include <sys/types.h> #include <sys/types.h>
#include <dirent.h> #include <dirent.h>
@ -72,6 +73,9 @@ void makePathReadOnly(const Path & path);
/* Create a temporary directory. */ /* Create a temporary directory. */
Path createTempDir(const Path & tmpRoot = ""); Path createTempDir(const Path & tmpRoot = "");
/* Create a state directory. */
Path createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const DerivationStateOutputs & stateOutputs);
/* Create a directory and all its parents, if necessary. */ /* Create a directory and all its parents, if necessary. */
void createDirs(const Path & path); void createDirs(const Path & path);