2024-04-02 00:59:30 +03:00
|
|
|
#include "nix/config.h"
|
2017-04-26 18:04:45 +03:00
|
|
|
|
2011-10-10 21:12:40 +03:00
|
|
|
#include "EXTERN.h"
|
|
|
|
#include "perl.h"
|
|
|
|
#include "XSUB.h"
|
|
|
|
|
|
|
|
/* Prevent a clash between some Perl and libstdc++ macros. */
|
|
|
|
#undef do_open
|
|
|
|
#undef do_close
|
|
|
|
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 15:28:26 +02:00
|
|
|
#include "derivations.hh"
|
2022-03-18 17:35:45 +02:00
|
|
|
#include "realisation.hh"
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 15:28:26 +02:00
|
|
|
#include "globals.hh"
|
|
|
|
#include "store-api.hh"
|
2023-11-04 22:25:41 +02:00
|
|
|
#include "posix-source-accessor.hh"
|
2011-10-10 21:12:40 +03:00
|
|
|
|
2015-02-04 17:43:32 +02:00
|
|
|
#include <sodium.h>
|
2021-07-30 12:55:14 +03:00
|
|
|
#include <nlohmann/json.hpp>
|
2015-02-04 17:43:32 +02:00
|
|
|
|
2011-10-10 21:12:40 +03:00
|
|
|
using namespace nix;
|
|
|
|
|
2024-01-26 22:54:33 +02:00
|
|
|
static bool libStoreInitialized = false;
|
2011-10-10 21:12:40 +03:00
|
|
|
|
2024-01-26 22:54:33 +02:00
|
|
|
struct StoreWrapper {
|
|
|
|
ref<Store> store;
|
|
|
|
};
|
2011-10-10 21:12:40 +03:00
|
|
|
|
|
|
|
MODULE = Nix::Store PACKAGE = Nix::Store
|
|
|
|
PROTOTYPES: ENABLE
|
|
|
|
|
2024-01-26 22:54:33 +02:00
|
|
|
TYPEMAP: <<HERE
|
|
|
|
StoreWrapper * O_OBJECT
|
|
|
|
|
|
|
|
OUTPUT
|
|
|
|
O_OBJECT
|
|
|
|
sv_setref_pv( $arg, CLASS, (void*)$var );
|
|
|
|
|
|
|
|
INPUT
|
|
|
|
O_OBJECT
|
|
|
|
if ( sv_isobject($arg) && (SvTYPE(SvRV($arg)) == SVt_PVMG) ) {
|
|
|
|
$var = ($type)SvIV((SV*)SvRV( $arg ));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
warn( \"${Package}::$func_name() -- \"
|
|
|
|
\"$var not a blessed SV reference\");
|
|
|
|
XSRETURN_UNDEF;
|
|
|
|
}
|
|
|
|
HERE
|
2011-10-10 21:12:40 +03:00
|
|
|
|
2014-01-21 17:38:03 +02:00
|
|
|
#undef dNOOP // Hack to work around "error: declaration of 'Perl___notused' has a different language linkage" error message on clang.
|
|
|
|
#define dNOOP
|
|
|
|
|
2024-01-26 22:54:33 +02:00
|
|
|
void
|
|
|
|
StoreWrapper::DESTROY()
|
|
|
|
|
|
|
|
StoreWrapper *
|
|
|
|
StoreWrapper::new(char * s = nullptr)
|
|
|
|
CODE:
|
|
|
|
static std::shared_ptr<Store> _store;
|
|
|
|
try {
|
|
|
|
if (!libStoreInitialized) {
|
|
|
|
initLibStore();
|
|
|
|
libStoreInitialized = true;
|
|
|
|
}
|
|
|
|
if (items == 1) {
|
|
|
|
_store = openStore();
|
|
|
|
RETVAL = new StoreWrapper {
|
|
|
|
.store = ref<Store>{_store}
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
RETVAL = new StoreWrapper {
|
|
|
|
.store = openStore(s)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} catch (Error & e) {
|
|
|
|
croak("%s", e.what());
|
|
|
|
}
|
|
|
|
OUTPUT:
|
|
|
|
RETVAL
|
|
|
|
|
2014-01-21 17:38:03 +02:00
|
|
|
|
2011-10-10 21:12:40 +03:00
|
|
|
void init()
|
|
|
|
CODE:
|
2024-01-26 22:54:33 +02:00
|
|
|
if (!libStoreInitialized) {
|
|
|
|
initLibStore();
|
|
|
|
libStoreInitialized = true;
|
|
|
|
}
|
2011-10-10 21:12:40 +03:00
|
|
|
|
|
|
|
|
2015-03-04 17:27:42 +02:00
|
|
|
void setVerbosity(int level)
|
|
|
|
CODE:
|
|
|
|
verbosity = (Verbosity) level;
|
|
|
|
|
|
|
|
|
2024-01-26 22:54:33 +02:00
|
|
|
int
|
|
|
|
StoreWrapper::isValidPath(char * path)
|
2011-10-10 21:12:40 +03:00
|
|
|
CODE:
|
|
|
|
try {
|
2024-01-26 22:54:33 +02:00
|
|
|
RETVAL = THIS->store->isValidPath(THIS->store->parseStorePath(path));
|
2011-10-10 21:12:40 +03:00
|
|
|
} catch (Error & e) {
|
2016-01-07 15:33:13 +02:00
|
|
|
croak("%s", e.what());
|
2011-10-10 21:12:40 +03:00
|
|
|
}
|
|
|
|
OUTPUT:
|
|
|
|
RETVAL
|
|
|
|
|
|
|
|
|
2024-01-26 22:54:33 +02:00
|
|
|
SV *
|
|
|
|
StoreWrapper::queryReferences(char * path)
|
2011-10-10 21:12:40 +03:00
|
|
|
PPCODE:
|
|
|
|
try {
|
2024-01-26 22:54:33 +02:00
|
|
|
for (auto & i : THIS->store->queryPathInfo(THIS->store->parseStorePath(path))->references)
|
|
|
|
XPUSHs(sv_2mortal(newSVpv(THIS->store->printStorePath(i).c_str(), 0)));
|
2011-10-10 21:12:40 +03:00
|
|
|
} catch (Error & e) {
|
2016-01-07 15:33:13 +02:00
|
|
|
croak("%s", e.what());
|
2011-10-10 21:12:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-26 22:54:33 +02:00
|
|
|
SV *
|
|
|
|
StoreWrapper::queryPathHash(char * path)
|
2011-10-10 21:12:40 +03:00
|
|
|
PPCODE:
|
|
|
|
try {
|
2024-01-26 22:54:33 +02:00
|
|
|
auto s = THIS->store->queryPathInfo(THIS->store->parseStorePath(path))->narHash.to_string(HashFormat::Nix32, true);
|
2011-10-10 21:12:40 +03:00
|
|
|
XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0)));
|
|
|
|
} catch (Error & e) {
|
2016-01-07 15:33:13 +02:00
|
|
|
croak("%s", e.what());
|
2011-10-10 21:12:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-26 22:54:33 +02:00
|
|
|
SV *
|
|
|
|
StoreWrapper::queryDeriver(char * path)
|
2011-10-10 21:12:40 +03:00
|
|
|
PPCODE:
|
|
|
|
try {
|
2024-01-26 22:54:33 +02:00
|
|
|
auto info = THIS->store->queryPathInfo(THIS->store->parseStorePath(path));
|
2019-12-05 20:11:09 +02:00
|
|
|
if (!info->deriver) XSRETURN_UNDEF;
|
2024-01-26 22:54:33 +02:00
|
|
|
XPUSHs(sv_2mortal(newSVpv(THIS->store->printStorePath(*info->deriver).c_str(), 0)));
|
2011-10-10 21:12:40 +03:00
|
|
|
} catch (Error & e) {
|
2016-01-07 15:33:13 +02:00
|
|
|
croak("%s", e.what());
|
2011-10-10 21:12:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-26 22:54:33 +02:00
|
|
|
SV *
|
|
|
|
StoreWrapper::queryPathInfo(char * path, int base32)
|
2011-10-10 21:12:40 +03:00
|
|
|
PPCODE:
|
|
|
|
try {
|
2024-01-26 22:54:33 +02:00
|
|
|
auto info = THIS->store->queryPathInfo(THIS->store->parseStorePath(path));
|
2020-03-10 12:00:17 +02:00
|
|
|
if (!info->deriver)
|
2011-10-10 21:12:40 +03:00
|
|
|
XPUSHs(&PL_sv_undef);
|
|
|
|
else
|
2024-01-26 22:54:33 +02:00
|
|
|
XPUSHs(sv_2mortal(newSVpv(THIS->store->printStorePath(*info->deriver).c_str(), 0)));
|
2023-12-03 10:50:44 +02:00
|
|
|
auto s = info->narHash.to_string(base32 ? HashFormat::Nix32 : HashFormat::Base16, true);
|
2011-10-10 21:12:40 +03:00
|
|
|
XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0)));
|
2016-04-19 19:50:15 +03:00
|
|
|
mXPUSHi(info->registrationTime);
|
|
|
|
mXPUSHi(info->narSize);
|
2020-11-22 00:06:15 +02:00
|
|
|
AV * refs = newAV();
|
2019-12-05 20:11:09 +02:00
|
|
|
for (auto & i : info->references)
|
2024-01-26 22:54:33 +02:00
|
|
|
av_push(refs, newSVpv(THIS->store->printStorePath(i).c_str(), 0));
|
2020-11-22 00:06:15 +02:00
|
|
|
XPUSHs(sv_2mortal(newRV((SV *) refs)));
|
|
|
|
AV * sigs = newAV();
|
|
|
|
for (auto & i : info->sigs)
|
|
|
|
av_push(sigs, newSVpv(i.c_str(), 0));
|
|
|
|
XPUSHs(sv_2mortal(newRV((SV *) sigs)));
|
2011-10-10 21:12:40 +03:00
|
|
|
} catch (Error & e) {
|
2016-01-07 15:33:13 +02:00
|
|
|
croak("%s", e.what());
|
2011-10-10 21:12:40 +03:00
|
|
|
}
|
|
|
|
|
2024-01-26 22:54:33 +02:00
|
|
|
SV *
|
|
|
|
StoreWrapper::queryRawRealisation(char * outputId)
|
2021-07-30 12:55:14 +03:00
|
|
|
PPCODE:
|
|
|
|
try {
|
2024-01-26 22:54:33 +02:00
|
|
|
auto realisation = THIS->store->queryRealisation(DrvOutput::parse(outputId));
|
2021-07-30 12:55:14 +03:00
|
|
|
if (realisation)
|
|
|
|
XPUSHs(sv_2mortal(newSVpv(realisation->toJSON().dump().c_str(), 0)));
|
|
|
|
else
|
|
|
|
XPUSHs(sv_2mortal(newSVpv("", 0)));
|
|
|
|
} catch (Error & e) {
|
|
|
|
croak("%s", e.what());
|
|
|
|
}
|
|
|
|
|
2011-10-10 21:12:40 +03:00
|
|
|
|
2024-01-26 22:54:33 +02:00
|
|
|
SV *
|
|
|
|
StoreWrapper::queryPathFromHashPart(char * hashPart)
|
2012-07-18 01:55:39 +03:00
|
|
|
PPCODE:
|
|
|
|
try {
|
2024-01-26 22:54:33 +02:00
|
|
|
auto path = THIS->store->queryPathFromHashPart(hashPart);
|
|
|
|
XPUSHs(sv_2mortal(newSVpv(path ? THIS->store->printStorePath(*path).c_str() : "", 0)));
|
2012-07-18 01:55:39 +03:00
|
|
|
} catch (Error & e) {
|
2016-01-07 15:33:13 +02:00
|
|
|
croak("%s", e.what());
|
2012-07-18 01:55:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-26 22:54:33 +02:00
|
|
|
SV *
|
|
|
|
StoreWrapper::computeFSClosure(int flipDirection, int includeOutputs, ...)
|
2011-10-10 21:12:40 +03:00
|
|
|
PPCODE:
|
|
|
|
try {
|
2019-12-05 20:11:09 +02:00
|
|
|
StorePathSet paths;
|
2011-10-10 21:12:40 +03:00
|
|
|
for (int n = 2; n < items; ++n)
|
2024-01-26 22:54:33 +02:00
|
|
|
THIS->store->computeFSClosure(THIS->store->parseStorePath(SvPV_nolen(ST(n))), paths, flipDirection, includeOutputs);
|
2019-12-05 20:11:09 +02:00
|
|
|
for (auto & i : paths)
|
2024-01-26 22:54:33 +02:00
|
|
|
XPUSHs(sv_2mortal(newSVpv(THIS->store->printStorePath(i).c_str(), 0)));
|
2011-10-10 21:12:40 +03:00
|
|
|
} catch (Error & e) {
|
2016-01-07 15:33:13 +02:00
|
|
|
croak("%s", e.what());
|
2011-10-10 21:12:40 +03:00
|
|
|
}
|
2011-10-11 18:41:13 +03:00
|
|
|
|
|
|
|
|
2024-01-26 22:54:33 +02:00
|
|
|
SV *
|
|
|
|
StoreWrapper::topoSortPaths(...)
|
2011-10-11 18:41:13 +03:00
|
|
|
PPCODE:
|
|
|
|
try {
|
2019-12-05 20:11:09 +02:00
|
|
|
StorePathSet paths;
|
2024-01-26 22:54:33 +02:00
|
|
|
for (int n = 0; n < items; ++n) paths.insert(THIS->store->parseStorePath(SvPV_nolen(ST(n))));
|
|
|
|
auto sorted = THIS->store->topoSortPaths(paths);
|
2019-12-05 20:11:09 +02:00
|
|
|
for (auto & i : sorted)
|
2024-01-26 22:54:33 +02:00
|
|
|
XPUSHs(sv_2mortal(newSVpv(THIS->store->printStorePath(i).c_str(), 0)));
|
2011-10-11 18:41:13 +03:00
|
|
|
} catch (Error & e) {
|
2016-01-07 15:33:13 +02:00
|
|
|
croak("%s", e.what());
|
2011-10-11 18:41:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-26 22:54:33 +02:00
|
|
|
SV *
|
|
|
|
StoreWrapper::followLinksToStorePath(char * path)
|
2011-10-11 18:41:13 +03:00
|
|
|
CODE:
|
|
|
|
try {
|
2024-01-26 22:54:33 +02:00
|
|
|
RETVAL = newSVpv(THIS->store->printStorePath(THIS->store->followLinksToStorePath(path)).c_str(), 0);
|
2011-10-11 18:41:13 +03:00
|
|
|
} catch (Error & e) {
|
2016-01-07 15:33:13 +02:00
|
|
|
croak("%s", e.what());
|
2011-10-11 18:41:13 +03:00
|
|
|
}
|
|
|
|
OUTPUT:
|
|
|
|
RETVAL
|
2011-11-23 17:13:37 +02:00
|
|
|
|
|
|
|
|
2024-01-26 22:54:33 +02:00
|
|
|
void
|
|
|
|
StoreWrapper::exportPaths(int fd, ...)
|
2011-11-23 17:13:37 +02:00
|
|
|
PPCODE:
|
|
|
|
try {
|
2019-12-05 20:11:09 +02:00
|
|
|
StorePathSet paths;
|
2024-01-26 22:54:33 +02:00
|
|
|
for (int n = 1; n < items; ++n) paths.insert(THIS->store->parseStorePath(SvPV_nolen(ST(n))));
|
2011-11-23 17:13:37 +02:00
|
|
|
FdSink sink(fd);
|
2024-01-26 22:54:33 +02:00
|
|
|
THIS->store->exportPaths(paths, sink);
|
2011-11-23 17:13:37 +02:00
|
|
|
} catch (Error & e) {
|
2016-01-07 15:33:13 +02:00
|
|
|
croak("%s", e.what());
|
2011-11-23 17:13:37 +02:00
|
|
|
}
|
2011-11-29 15:01:24 +02:00
|
|
|
|
|
|
|
|
2024-01-26 22:54:33 +02:00
|
|
|
void
|
|
|
|
StoreWrapper::importPaths(int fd, int dontCheckSigs)
|
2014-07-11 17:02:19 +03:00
|
|
|
PPCODE:
|
|
|
|
try {
|
|
|
|
FdSource source(fd);
|
2024-01-26 22:54:33 +02:00
|
|
|
THIS->store->importPaths(source, dontCheckSigs ? NoCheckSigs : CheckSigs);
|
2014-07-11 17:02:19 +03:00
|
|
|
} catch (Error & e) {
|
2016-01-07 15:33:13 +02:00
|
|
|
croak("%s", e.what());
|
2014-07-11 17:02:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-26 22:54:33 +02:00
|
|
|
SV *
|
|
|
|
hashPath(char * algo, int base32, char * path)
|
2011-11-29 15:01:24 +02:00
|
|
|
PPCODE:
|
|
|
|
try {
|
2023-11-04 22:25:41 +02:00
|
|
|
Hash h = hashPath(
|
2024-05-06 21:00:44 +03:00
|
|
|
PosixSourceAccessor::createAtRoot(path),
|
2024-05-07 20:25:44 +03:00
|
|
|
FileIngestionMethod::Recursive, parseHashAlgo(algo)).first;
|
2023-12-03 10:50:44 +02:00
|
|
|
auto s = h.to_string(base32 ? HashFormat::Nix32 : HashFormat::Base16, false);
|
2011-11-29 15:01:24 +02:00
|
|
|
XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0)));
|
|
|
|
} catch (Error & e) {
|
2016-01-07 15:33:13 +02:00
|
|
|
croak("%s", e.what());
|
2011-11-29 15:01:24 +02:00
|
|
|
}
|
2011-12-02 14:09:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
SV * hashFile(char * algo, int base32, char * path)
|
|
|
|
PPCODE:
|
|
|
|
try {
|
2023-11-28 15:20:27 +02:00
|
|
|
Hash h = hashFile(parseHashAlgo(algo), path);
|
2023-12-03 10:50:44 +02:00
|
|
|
auto s = h.to_string(base32 ? HashFormat::Nix32 : HashFormat::Base16, false);
|
2011-12-02 14:09:24 +02:00
|
|
|
XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0)));
|
|
|
|
} catch (Error & e) {
|
2016-01-07 15:33:13 +02:00
|
|
|
croak("%s", e.what());
|
2011-12-02 14:09:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SV * hashString(char * algo, int base32, char * s)
|
|
|
|
PPCODE:
|
|
|
|
try {
|
2023-11-28 15:20:27 +02:00
|
|
|
Hash h = hashString(parseHashAlgo(algo), s);
|
2023-12-03 10:50:44 +02:00
|
|
|
auto s = h.to_string(base32 ? HashFormat::Nix32 : HashFormat::Base16, false);
|
2011-12-02 14:09:24 +02:00
|
|
|
XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0)));
|
|
|
|
} catch (Error & e) {
|
2016-01-07 15:33:13 +02:00
|
|
|
croak("%s", e.what());
|
2011-12-02 14:09:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-03 16:33:17 +03:00
|
|
|
SV * convertHash(char * algo, char * s, int toBase32)
|
|
|
|
PPCODE:
|
|
|
|
try {
|
2023-11-28 15:20:27 +02:00
|
|
|
auto h = Hash::parseAny(s, parseHashAlgo(algo));
|
2023-12-03 10:50:44 +02:00
|
|
|
auto s = h.to_string(toBase32 ? HashFormat::Nix32 : HashFormat::Base16, false);
|
2015-06-03 16:33:17 +03:00
|
|
|
XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0)));
|
|
|
|
} catch (Error & e) {
|
2016-01-07 15:33:13 +02:00
|
|
|
croak("%s", e.what());
|
2015-06-03 16:33:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-16 17:38:44 +02:00
|
|
|
SV * signString(char * secretKey_, char * msg)
|
2015-02-04 17:43:32 +02:00
|
|
|
PPCODE:
|
|
|
|
try {
|
2016-02-16 17:38:44 +02:00
|
|
|
auto sig = SecretKey(secretKey_).signDetached(msg);
|
|
|
|
XPUSHs(sv_2mortal(newSVpv(sig.c_str(), sig.size())));
|
2015-02-04 17:43:32 +02:00
|
|
|
} catch (Error & e) {
|
2016-01-07 15:33:13 +02:00
|
|
|
croak("%s", e.what());
|
2015-02-04 17:43:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int checkSignature(SV * publicKey_, SV * sig_, char * msg)
|
|
|
|
CODE:
|
|
|
|
try {
|
|
|
|
STRLEN publicKeyLen;
|
|
|
|
unsigned char * publicKey = (unsigned char *) SvPV(publicKey_, publicKeyLen);
|
|
|
|
if (publicKeyLen != crypto_sign_PUBLICKEYBYTES)
|
|
|
|
throw Error("public key is not valid");
|
|
|
|
|
|
|
|
STRLEN sigLen;
|
|
|
|
unsigned char * sig = (unsigned char *) SvPV(sig_, sigLen);
|
|
|
|
if (sigLen != crypto_sign_BYTES)
|
|
|
|
throw Error("signature is not valid");
|
|
|
|
|
|
|
|
RETVAL = crypto_sign_verify_detached(sig, (unsigned char *) msg, strlen(msg), publicKey) == 0;
|
|
|
|
} catch (Error & e) {
|
2016-01-07 15:33:13 +02:00
|
|
|
croak("%s", e.what());
|
2015-02-04 17:43:32 +02:00
|
|
|
}
|
|
|
|
OUTPUT:
|
|
|
|
RETVAL
|
|
|
|
|
|
|
|
|
2024-01-26 22:54:33 +02:00
|
|
|
SV *
|
|
|
|
StoreWrapper::addToStore(char * srcPath, int recursive, char * algo)
|
2011-12-02 14:09:24 +02:00
|
|
|
PPCODE:
|
|
|
|
try {
|
2020-03-31 01:40:41 +03:00
|
|
|
auto method = recursive ? FileIngestionMethod::Recursive : FileIngestionMethod::Flat;
|
2024-01-26 22:54:33 +02:00
|
|
|
auto path = THIS->store->addToStore(
|
2023-11-04 22:25:41 +02:00
|
|
|
std::string(baseNameOf(srcPath)),
|
2024-05-06 21:00:44 +03:00
|
|
|
PosixSourceAccessor::createAtRoot(srcPath),
|
2023-11-04 22:25:41 +02:00
|
|
|
method, parseHashAlgo(algo));
|
2024-01-26 22:54:33 +02:00
|
|
|
XPUSHs(sv_2mortal(newSVpv(THIS->store->printStorePath(path).c_str(), 0)));
|
2011-12-02 14:09:24 +02:00
|
|
|
} catch (Error & e) {
|
2016-01-07 15:33:13 +02:00
|
|
|
croak("%s", e.what());
|
2011-12-02 14:09:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-26 22:54:33 +02:00
|
|
|
SV *
|
|
|
|
StoreWrapper::makeFixedOutputPath(int recursive, char * algo, char * hash, char * name)
|
2011-12-02 14:09:24 +02:00
|
|
|
PPCODE:
|
|
|
|
try {
|
2023-11-28 15:20:27 +02:00
|
|
|
auto h = Hash::parseAny(hash, parseHashAlgo(algo));
|
2020-03-31 01:40:41 +03:00
|
|
|
auto method = recursive ? FileIngestionMethod::Recursive : FileIngestionMethod::Flat;
|
2024-01-26 22:54:33 +02:00
|
|
|
auto path = THIS->store->makeFixedOutputPath(name, FixedOutputInfo {
|
2023-07-06 01:53:44 +03:00
|
|
|
.method = method,
|
|
|
|
.hash = h,
|
2023-02-28 18:57:20 +02:00
|
|
|
.references = {},
|
2020-10-07 16:52:20 +03:00
|
|
|
});
|
2024-01-26 22:54:33 +02:00
|
|
|
XPUSHs(sv_2mortal(newSVpv(THIS->store->printStorePath(path).c_str(), 0)));
|
2011-12-02 14:09:24 +02:00
|
|
|
} catch (Error & e) {
|
2016-01-07 15:33:13 +02:00
|
|
|
croak("%s", e.what());
|
2011-12-02 14:09:24 +02:00
|
|
|
}
|
2012-03-19 05:14:21 +02:00
|
|
|
|
|
|
|
|
2024-01-26 22:54:33 +02:00
|
|
|
SV *
|
|
|
|
StoreWrapper::derivationFromPath(char * drvPath)
|
2012-03-19 05:14:21 +02:00
|
|
|
PREINIT:
|
|
|
|
HV *hash;
|
|
|
|
CODE:
|
|
|
|
try {
|
2024-01-26 22:54:33 +02:00
|
|
|
Derivation drv = THIS->store->derivationFromPath(THIS->store->parseStorePath(drvPath));
|
2012-03-19 05:14:21 +02:00
|
|
|
hash = newHV();
|
2013-03-08 02:24:59 +02:00
|
|
|
|
|
|
|
HV * outputs = newHV();
|
2024-01-26 22:54:33 +02:00
|
|
|
for (auto & i : drv.outputsAndOptPaths(*THIS->store)) {
|
2020-07-12 21:26:10 +03:00
|
|
|
hv_store(
|
|
|
|
outputs, i.first.c_str(), i.first.size(),
|
2020-08-14 20:00:13 +03:00
|
|
|
!i.second.second
|
2020-08-08 18:48:51 +03:00
|
|
|
? newSV(0) /* null value */
|
2024-01-26 22:54:33 +02:00
|
|
|
: newSVpv(THIS->store->printStorePath(*i.second.second).c_str(), 0),
|
2020-07-12 21:26:10 +03:00
|
|
|
0);
|
2020-08-08 18:48:51 +03:00
|
|
|
}
|
2013-03-08 02:24:59 +02:00
|
|
|
hv_stores(hash, "outputs", newRV((SV *) outputs));
|
|
|
|
|
2012-03-19 05:14:21 +02:00
|
|
|
AV * inputDrvs = newAV();
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
for (auto & i : drv.inputDrvs.map)
|
2024-01-26 22:54:33 +02:00
|
|
|
av_push(inputDrvs, newSVpv(THIS->store->printStorePath(i.first).c_str(), 0)); // !!! ignores i->second
|
2012-03-19 05:14:21 +02:00
|
|
|
hv_stores(hash, "inputDrvs", newRV((SV *) inputDrvs));
|
2013-03-08 02:24:59 +02:00
|
|
|
|
2012-03-19 05:14:21 +02:00
|
|
|
AV * inputSrcs = newAV();
|
2019-12-05 20:11:09 +02:00
|
|
|
for (auto & i : drv.inputSrcs)
|
2024-01-26 22:54:33 +02:00
|
|
|
av_push(inputSrcs, newSVpv(THIS->store->printStorePath(i).c_str(), 0));
|
2012-03-19 05:14:21 +02:00
|
|
|
hv_stores(hash, "inputSrcs", newRV((SV *) inputSrcs));
|
2013-03-08 02:24:59 +02:00
|
|
|
|
2012-03-19 05:14:21 +02:00
|
|
|
hv_stores(hash, "platform", newSVpv(drv.platform.c_str(), 0));
|
|
|
|
hv_stores(hash, "builder", newSVpv(drv.builder.c_str(), 0));
|
2013-03-08 02:24:59 +02:00
|
|
|
|
2012-03-19 05:14:21 +02:00
|
|
|
AV * args = newAV();
|
2019-12-05 20:11:09 +02:00
|
|
|
for (auto & i : drv.args)
|
|
|
|
av_push(args, newSVpv(i.c_str(), 0));
|
2012-03-19 05:14:21 +02:00
|
|
|
hv_stores(hash, "args", newRV((SV *) args));
|
2013-03-08 02:24:59 +02:00
|
|
|
|
2012-03-19 05:14:21 +02:00
|
|
|
HV * env = newHV();
|
2019-12-05 20:11:09 +02:00
|
|
|
for (auto & i : drv.env)
|
|
|
|
hv_store(env, i.first.c_str(), i.first.size(), newSVpv(i.second.c_str(), 0), 0);
|
2012-03-19 05:14:21 +02:00
|
|
|
hv_stores(hash, "env", newRV((SV *) env));
|
2013-03-08 02:24:59 +02:00
|
|
|
|
2012-03-19 05:14:21 +02:00
|
|
|
RETVAL = newRV_noinc((SV *)hash);
|
|
|
|
} catch (Error & e) {
|
2016-01-07 15:33:13 +02:00
|
|
|
croak("%s", e.what());
|
2012-03-19 05:14:21 +02:00
|
|
|
}
|
|
|
|
OUTPUT:
|
|
|
|
RETVAL
|
2015-10-09 13:49:47 +03:00
|
|
|
|
|
|
|
|
2024-01-26 22:54:33 +02:00
|
|
|
void
|
|
|
|
StoreWrapper::addTempRoot(char * storePath)
|
2015-10-09 13:49:47 +03:00
|
|
|
PPCODE:
|
|
|
|
try {
|
2024-01-26 22:54:33 +02:00
|
|
|
THIS->store->addTempRoot(THIS->store->parseStorePath(storePath));
|
2015-10-09 13:49:47 +03:00
|
|
|
} catch (Error & e) {
|
2016-01-07 15:33:13 +02:00
|
|
|
croak("%s", e.what());
|
2015-10-09 13:49:47 +03:00
|
|
|
}
|
2020-09-17 11:42:51 +03:00
|
|
|
|
|
|
|
|
|
|
|
SV * getBinDir()
|
|
|
|
PPCODE:
|
|
|
|
XPUSHs(sv_2mortal(newSVpv(settings.nixBinDir.c_str(), 0)));
|
|
|
|
|
|
|
|
|
|
|
|
SV * getStoreDir()
|
|
|
|
PPCODE:
|
|
|
|
XPUSHs(sv_2mortal(newSVpv(settings.nixStore.c_str(), 0)));
|