diff --git a/pkgs/nix/cvmfs.patch b/pkgs/nix/cvmfs.patch index 7ec5b35..78b10ef 100644 --- a/pkgs/nix/cvmfs.patch +++ b/pkgs/nix/cvmfs.patch @@ -1,12 +1,12 @@ -diff --git a/scripts/nix-build.in b/scripts/nix-build.in -index bb61e1c..d58d687 100755 ---- a/scripts/nix-build.in -+++ b/scripts/nix-build.in -@@ -276,6 +276,7 @@ foreach my $expr (@exprs) { - } - # NixOS hack: prevent /etc/bashrc from sourcing /etc/profile. - $ENV{'__ETC_PROFILE_SOURCED'} = 1; -+ $ENV{'SKIP_CC_CVMFS'} = 1; +diff --git a/src/nix-build/nix-build.cc b/src/nix-build/nix-build.cc +index 99f77345..4f71fca1 100755 +--- a/src/nix-build/nix-build.cc ++++ b/src/nix-build/nix-build.cc +@@ -372,6 +372,7 @@ void mainWrapped(int argc, char * * argv) + env = newEnv; + // NixOS hack: prevent /etc/bashrc from sourcing /etc/profile. + env["__ETC_PROFILE_SOURCED"] = "1"; ++ env["SKIP_CC_CVMFS"] = "1"; } - $ENV{'NIX_BUILD_TOP'} = $ENV{'TMPDIR'} = $ENV{'TEMPDIR'} = $ENV{'TMP'} = $ENV{'TEMP'} = $tmp; - $ENV{'NIX_STORE'} = $Nix::Config::storeDir; + + env["NIX_BUILD_TOP"] = env["TMPDIR"] = env["TEMPDIR"] = env["TMP"] = env["TEMP"] = tmp; diff --git a/pkgs/nix/remote.patch b/pkgs/nix/remote.patch index d6a50a4..cee559b 100644 --- a/pkgs/nix/remote.patch +++ b/pkgs/nix/remote.patch @@ -1,52 +1,47 @@ diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc -index 262e465..1bee9a6 100644 +index 8f0b6555..b874e760 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc -@@ -16,6 +16,7 @@ - - #include +@@ -15,6 +15,7 @@ + #include + #include #include +#include + #include - namespace nix { -@@ -55,9 +56,9 @@ void RemoteStore::openConnection(bool reserveSpace) - if (remoteMode == "daemon") - /* Connect to a daemon that does the privileged work for - us. */ -- connectToDaemon(); -+ connectToDaemonUNIX(); - else -- throw Error(format("invalid setting for NIX_REMOTE, ‘%1%’") % remoteMode); -+ connectToDaemonINET(remoteMode); - - from.fd = fdSocket; - to.fd = fdSocket; -@@ -95,7 +96,7 @@ void RemoteStore::openConnection(bool reserveSpace) +@@ -133,6 +134,76 @@ ref UDSRemoteStore::openConnection() } --void RemoteStore::connectToDaemon() -+void RemoteStore::connectToDaemonUNIX() - { - fdSocket = socket(PF_UNIX, SOCK_STREAM, 0); - if (fdSocket == -1) -@@ -128,6 +129,53 @@ void RemoteStore::connectToDaemon() - } - - -+ -+void RemoteStore::connectToDaemonINET(const string & remoteAddress) ++TCPRemoteStore::TCPRemoteStore(std::string tcp_path, const Params & params) ++ : Store(params) ++ , LocalFSStore(params) ++ , RemoteStore(params) ++ , path(tcp_path) +{ -+ size_t remoteColonOffset = remoteAddress.find(':'); -+ if (remoteColonOffset == string::npos) -+ throw Error(format("invalid daemon address ‘%1%’ (should be daemon or host:port)") % remoteAddress); ++} + -+ string remoteHost = remoteAddress.substr(0,remoteColonOffset); -+ string remoteService = remoteAddress.substr(remoteColonOffset+1); ++ ++std::string TCPRemoteStore::getUri() ++{ ++ return std::string("tcp://") + path; ++} ++ ++ ++ref TCPRemoteStore::openConnection() ++{ ++ auto conn = make_ref(); ++ ++ size_t remoteColonOffset = path.find(':'); ++ if (remoteColonOffset == string::npos) ++ throw Error(format("invalid daemon address '%1%' (should be host:port)") % path); ++ ++ string remoteHost = path.substr(0,remoteColonOffset); ++ string remoteService = path.substr(remoteColonOffset+1); + + addrinfo addrHints; -+ addrinfo* addrResults; ++ addrinfo* addrResults_raw; + + memset(&addrHints,0,sizeof(addrHints)); + addrHints.ai_flags = AI_ADDRCONFIG | AI_V4MAPPED; @@ -54,48 +49,91 @@ index 262e465..1bee9a6 100644 + addrHints.ai_socktype = SOCK_STREAM; + addrHints.ai_protocol = 0; + -+ int result = getaddrinfo(remoteHost.c_str(), remoteService.c_str(), &addrHints, &addrResults); ++ int result = getaddrinfo(remoteHost.c_str(), remoteService.c_str(), &addrHints, &addrResults_raw); + if (result != 0) -+ throw Error(format("unable to lookup daemon address ‘%1%’") % remoteAddress); -+ std::unique_ptr addrResults_gc(addrResults,freeaddrinfo); ++ throw Error(format("unable to lookup daemon address '%1%'") % path); ++ std::unique_ptr addrResults(addrResults_raw,freeaddrinfo); + -+ int remoteSocket; + addrinfo* addrIter; -+ for (addrIter = addrResults; addrIter; addrIter = addrIter->ai_next) { -+ remoteSocket = socket(addrIter->ai_family, addrIter->ai_socktype, addrIter->ai_protocol); -+ if (remoteSocket == -1) ++ for (addrIter = addrResults.get(); addrIter; addrIter = addrIter->ai_next) { ++ AutoCloseFD remoteSocket = socket(addrIter->ai_family, addrIter->ai_socktype ++ #ifdef SOCK_CLOEXEC ++ | SOCK_CLOEXEC ++ #endif ++ , addrIter->ai_protocol); ++ if (!remoteSocket) + continue; + -+ int result = connect(remoteSocket, addrIter->ai_addr, addrIter->ai_addrlen); -+ if (result == -1) { -+ close(remoteSocket); ++ if (::connect(remoteSocket.get(), addrIter->ai_addr, addrIter->ai_addrlen) == -1) + continue; -+ } + -+ fdSocket = remoteSocket; ++ conn->fd = std::move(remoteSocket); + break; + } + if (addrIter == 0) -+ throw Error(format("unable to connect to daemon at ‘%1%’") % remoteAddress); ++ throw Error(format("unable to connect to daemon at '%1%'") % path); + -+ fdSocket = remoteSocket; ++ conn->from.fd = conn->fd.get(); ++ conn->to.fd = conn->fd.get(); ++ ++ conn->startTime = std::chrono::steady_clock::now(); ++ ++ initConnection(*conn); ++ ++ return conn; +} + + - RemoteStore::~RemoteStore() + void RemoteStore::initConnection(Connection & conn) { - try { + /* Send the magic greeting, check for the reply. */ +@@ -734,14 +805,18 @@ void RemoteStore::Connection::processStderr(Sink * sink, Source * source) + } + } + +-static std::string uriScheme = "unix://"; ++static std::string uriSchemeUnix = "unix://"; ++static std::string uriSchemeTCP = "tcp://"; + + static RegisterStoreImplementation regStore([]( + const std::string & uri, const Store::Params & params) + -> std::shared_ptr + { +- if (std::string(uri, 0, uriScheme.size()) != uriScheme) return 0; +- return std::make_shared(std::string(uri, uriScheme.size()), params); ++ if (std::string(uri, 0, uriSchemeUnix.size()) == uriSchemeUnix) ++ return std::make_shared(std::string(uri, uriSchemeUnix.size()), params); ++ if (std::string(uri, 0, uriSchemeTCP.size()) == uriSchemeTCP) ++ return std::make_shared(std::string(uri, uriSchemeTCP.size()), params); ++ return 0; + }); + + } diff --git a/src/libstore/remote-store.hh b/src/libstore/remote-store.hh -index b0787c0..6fd404f 100644 +index 7f36e206..544b76eb 100644 --- a/src/libstore/remote-store.hh +++ b/src/libstore/remote-store.hh -@@ -101,7 +101,8 @@ private: - - void processStderr(Sink * sink = 0, Source * source = 0); - -- void connectToDaemon(); -+ void connectToDaemonUNIX(); -+ void connectToDaemonINET(const string & remoteAddress); - - void setOptions(); +@@ -149,5 +149,23 @@ private: + std::experimental::optional path; }; + ++class TCPRemoteStore : public LocalFSStore, public RemoteStore ++{ ++public: ++ ++ TCPRemoteStore(std::string path, const Params & params); ++ ++ std::string getUri() override; ++ ++private: ++ ++ struct Connection : RemoteStore::Connection ++ { ++ AutoCloseFD fd; ++ }; ++ ++ ref openConnection() override; ++ std::string path; ++}; + + } diff --git a/temporary/all-temporary.nix b/temporary/all-temporary.nix index 125f2ab..76fc72b 100644 --- a/temporary/all-temporary.nix +++ b/temporary/all-temporary.nix @@ -7,9 +7,4 @@ self: super: pkgs: with pkgs; { - # https://github.com/NixOS/nix/pull/1645 - nixStable = super.nixStable.overrideAttrs - ( attrs: { patches = attrs.patches or [] ++ [ ./nix/stat.patch ]; } ); - nix = super.nix.overrideAttrs - ( attrs: { patches = attrs.patches or [] ++ [ ./nix/stat.patch ]; } ); } diff --git a/temporary/nix/stat.patch b/temporary/nix/stat.patch deleted file mode 100644 index bee5a3c..0000000 --- a/temporary/nix/stat.patch +++ /dev/null @@ -1,33 +0,0 @@ -diff --git a/src/libutil/util.cc b/src/libutil/util.cc -index 0b11330..4c1dff2 100644 ---- a/src/libutil/util.cc -+++ b/src/libutil/util.cc -@@ -198,17 +198,17 @@ bool pathExists(const Path & path) - Path readLink(const Path & path) - { - checkInterrupt(); -- struct stat st = lstat(path); -- if (!S_ISLNK(st.st_mode)) -- throw Error(format("‘%1%’ is not a symlink") % path); -- char buf[st.st_size]; -- ssize_t rlsize = readlink(path.c_str(), buf, st.st_size); -- if (rlsize == -1) -- throw SysError(format("reading symbolic link ‘%1%’") % path); -- else if (rlsize > st.st_size) -- throw Error(format("symbolic link ‘%1%’ size overflow %2% > %3%") -- % path % rlsize % st.st_size); -- return string(buf, st.st_size); -+ for (ssize_t bufSize = PATH_MAX/4; true; bufSize += bufSize/2) { -+ char buf[bufSize]; -+ ssize_t rlSize = readlink(path.c_str(), buf, bufSize); -+ if (rlSize == -1) -+ if (errno == EINVAL) -+ throw Error(format("'%1%' is not a symlink") % path); -+ else -+ throw SysError(format("reading symbolic link '%1%'") % path); -+ else if (rlSize < bufSize) -+ return string(buf, rlSize); -+ } - } - -