diff --git a/nix/libstore/build.cc b/nix/libstore/build.cc index 9010ca4e200..935f7aacf83 100644 --- a/nix/libstore/build.cc +++ b/nix/libstore/build.cc @@ -3367,9 +3367,6 @@ void DerivationGoal::registerOutputs() } -string drvsLogDir = "drvs"; - - Path DerivationGoal::openLogFile() { logSize = 0; diff --git a/nix/libstore/derivations.cc b/nix/libstore/derivations.cc index f05296702b3..b6203b1e385 100644 --- a/nix/libstore/derivations.cc +++ b/nix/libstore/derivations.cc @@ -211,9 +211,6 @@ bool isFixedOutputDrv(const Derivation & drv) } -DrvHashes drvHashes; - - /* Returns the hash of a derivation modulo fixed-output subderivations. A fixed-output derivation is a derivation with one output (`out') for which an expected hash and hash algorithm are diff --git a/nix/libstore/derivations.hh b/nix/libstore/derivations.hh index 8d5e4d05d46..0fbab3a7a4a 100644 --- a/nix/libstore/derivations.hh +++ b/nix/libstore/derivations.hh @@ -77,7 +77,7 @@ Hash hashDerivationModulo(StoreAPI & store, Derivation drv); /* Memoisation of hashDerivationModulo(). */ typedef std::map DrvHashes; -extern DrvHashes drvHashes; +inline DrvHashes drvHashes; /* Split a string specifying a derivation and a set of outputs (/nix/store/hash-foo!out1,out2,...) into the derivation path and diff --git a/nix/libstore/globals.cc b/nix/libstore/globals.cc index 8551fea56c0..885ba4eafc1 100644 --- a/nix/libstore/globals.cc +++ b/nix/libstore/globals.cc @@ -17,9 +17,6 @@ namespace nix { #define DEFAULT_SOCKET_PATH "/daemon-socket/socket" -Settings settings; - - Settings::Settings() { keepFailed = false; @@ -205,7 +202,4 @@ Settings::SettingsMap Settings::getOverrides() } -const string nixVersion = PACKAGE_VERSION; - - } diff --git a/nix/libstore/globals.hh b/nix/libstore/globals.hh index 7cfa06e76c1..c2824789ede 100644 --- a/nix/libstore/globals.hh +++ b/nix/libstore/globals.hh @@ -227,10 +227,10 @@ private: // FIXME: don't use a global variable. -extern Settings settings; +inline Settings settings; -extern const string nixVersion; +inline const string nixVersion {PACKAGE_VERSION}; } diff --git a/nix/libstore/local-store.hh b/nix/libstore/local-store.hh index 20d3c3c8930..4d529b37a44 100644 --- a/nix/libstore/local-store.hh +++ b/nix/libstore/local-store.hh @@ -19,7 +19,7 @@ namespace nix { const int nixSchemaVersion = 7; -extern string drvsLogDir; +inline std::string drvsLogDir {"drvs"}; struct Derivation; @@ -293,6 +293,8 @@ void canonicaliseTimestampAndPermissions(const Path & path); MakeError(PathInUse, Error); /* Size below which a file is not considered for deduplication. */ -extern const size_t deduplicationMinSize; +/* Any file smaller than this is not considered for deduplication. + Keep in sync with (guix store deduplication). */ +inline const size_t deduplicationMinSize {8192}; } diff --git a/nix/libstore/optimise-store.cc b/nix/libstore/optimise-store.cc index d69c43e9978..54aa166c344 100644 --- a/nix/libstore/optimise-store.cc +++ b/nix/libstore/optimise-store.cc @@ -16,9 +16,6 @@ namespace nix { -/* Any file smaller than this is not considered for deduplication. - Keep in sync with (guix store deduplication). */ -const size_t deduplicationMinSize = 8192; static void makeWritable(const Path & path) { diff --git a/nix/libstore/store-api.cc b/nix/libstore/store-api.cc index 1067e44a8e2..26d44f78b19 100644 --- a/nix/libstore/store-api.cc +++ b/nix/libstore/store-api.cc @@ -253,16 +253,3 @@ template T readStorePaths(Source & from) template PathSet readStorePaths(Source & from); } - - -#include "local-store.hh" -#include "serialise.hh" - - -namespace nix { - - -std::shared_ptr store; - - -} diff --git a/nix/libstore/store-api.hh b/nix/libstore/store-api.hh index 32a8f2c795f..affa98b179d 100644 --- a/nix/libstore/store-api.hh +++ b/nix/libstore/store-api.hh @@ -363,7 +363,7 @@ Paths topoSortPaths(StoreAPI & store, const PathSet & paths); /* For now, there is a single global store API object, but we'll purify that in the future. */ -extern std::shared_ptr store; +inline std::shared_ptr store; /* Display a set of paths in human-readable form (i.e., between quotes diff --git a/nix/libutil/archive.cc b/nix/libutil/archive.cc index fa9f4398e3c..938fe8d4492 100644 --- a/nix/libutil/archive.cc +++ b/nix/libutil/archive.cc @@ -24,8 +24,6 @@ static string archiveVersion1 = "nix-archive-1"; static string caseHackSuffix = "~nix~case~hack~"; -PathFilter defaultPathFilter; - static void dumpContents(const Path & path, size_t size, Sink & sink) diff --git a/nix/libutil/archive.hh b/nix/libutil/archive.hh index 9b83a5f288f..03716ab469f 100644 --- a/nix/libutil/archive.hh +++ b/nix/libutil/archive.hh @@ -50,7 +50,7 @@ struct PathFilter virtual bool operator () (const Path & path) { return true; } }; -extern PathFilter defaultPathFilter; +inline PathFilter defaultPathFilter; void dumpPath(const Path & path, Sink & sink, PathFilter & filter = defaultPathFilter); diff --git a/nix/libutil/hash.cc b/nix/libutil/hash.cc index 57b369d4a9b..ac9eb14514b 100644 --- a/nix/libutil/hash.cc +++ b/nix/libutil/hash.cc @@ -103,10 +103,6 @@ unsigned int hashLength32(const Hash & hash) } -// omitted: E O U T -const string base32Chars = "0123456789abcdfghijklmnpqrsvwxyz"; - - string printHash32(const Hash & hash) { Hash hash2(hash); diff --git a/nix/libutil/hash.hh b/nix/libutil/hash.hh index 1a6b35f074b..cedb5077c16 100644 --- a/nix/libutil/hash.hh +++ b/nix/libutil/hash.hh @@ -2,14 +2,15 @@ #include +#include "archive.hh" #include "types.hh" #include "serialise.hh" namespace nix { - -extern const string base32Chars; +// omitted: E O U T +inline const string base32Chars {"0123456789abcdfghijklmnpqrsvwxyz"}; typedef enum { htUnknown = 0, @@ -79,8 +80,6 @@ Hash hashFile(HashType ht, const Path & path); /* Compute the hash of the given path. The hash is defined as (essentially) hashString(ht, dumpPath(path)). */ -struct PathFilter; -extern PathFilter defaultPathFilter; typedef std::pair HashResult; HashResult hashPath(HashType ht, const Path & path, PathFilter & filter = defaultPathFilter); diff --git a/nix/libutil/util.cc b/nix/libutil/util.cc index 22022db51a5..ed1a371dfe1 100644 --- a/nix/libutil/util.cc +++ b/nix/libutil/util.cc @@ -600,9 +600,6 @@ void createSymlink(const Path & target, const Path & link) } -LogType logType = ltPretty; -Verbosity verbosity = lvlInfo; - static int nestingLevel = 0; @@ -691,9 +688,6 @@ void writeToStderr(const string & s) } -void (*_writeToStderr) (const unsigned char * buf, size_t count) = 0; - - void readFull(int fd, unsigned char * buf, size_t count) { while (count) { @@ -1250,7 +1244,6 @@ void keepOnExec(int fd) ////////////////////////////////////////////////////////////////////// -volatile sig_atomic_t _isInterrupted = 0; void _interrupted() { diff --git a/nix/libutil/util.hh b/nix/libutil/util.hh index 436c378cb6e..42cb60ea0d4 100644 --- a/nix/libutil/util.hh +++ b/nix/libutil/util.hh @@ -132,8 +132,8 @@ typedef enum { ltFlat /* no nesting */ } LogType; -extern LogType logType; -extern Verbosity verbosity; /* suppress msgs > this */ +inline LogType logType {ltPretty}; +inline Verbosity verbosity {lvlInfo}; /* suppress msgs > this */ class Nest { @@ -167,7 +167,7 @@ void warnOnce(bool & haveWarned, std::string_view fs); void writeToStderr(const string & s); -extern void (*_writeToStderr) (const unsigned char * buf, size_t count); +inline void (*_writeToStderr) (const unsigned char * buf, size_t count) = 0; /* Wrappers arount read()/write() that read/write exactly the @@ -323,7 +323,7 @@ void commonChildInit(Pipe & logPipe); /* User interruption. */ -extern volatile sig_atomic_t _isInterrupted; +inline volatile sig_atomic_t _isInterrupted = 0; void _interrupted(); diff --git a/nix/local.mk b/nix/local.mk index 819131b5d44..2c93670843c 100644 --- a/nix/local.mk +++ b/nix/local.mk @@ -113,7 +113,7 @@ guix_daemon_LDADD = \ $(SQLITE3_LIBS) $(LIBGCRYPT_LIBS) guix_daemon_headers = \ - %D%/nix-daemon/shared.hh + %D%/nix-daemon/nix-daemon.hh if HAVE_LIBBZ2 diff --git a/nix/nix-daemon/guix-daemon.cc b/nix/nix-daemon/guix-daemon.cc index af09839932f..341e39c2907 100644 --- a/nix/nix-daemon/guix-daemon.cc +++ b/nix/nix-daemon/guix-daemon.cc @@ -17,12 +17,12 @@ You should have received a copy of the GNU General Public License along with GNU Guix. If not, see . */ -#include +#include "config.h" -#include -#include "shared.hh" -#include -#include +#include "types.hh" +#include "nix-daemon.hh" +#include "globals.hh" +#include "util.hh" #include @@ -36,20 +36,13 @@ #include #include #include -#include #include #include #include -/* Variables used by `nix-daemon.cc'. */ -volatile ::sig_atomic_t blockInt; -char **argvSaved; - using namespace nix; -/* Entry point in `nix-daemon.cc'. */ -extern void run (const std::vector &); /* Command-line options. */ diff --git a/nix/nix-daemon/nix-daemon.cc b/nix/nix-daemon/nix-daemon.cc index 3890adb2c74..b3cdb699ac2 100644 --- a/nix/nix-daemon/nix-daemon.cc +++ b/nix/nix-daemon/nix-daemon.cc @@ -1,5 +1,5 @@ #include "config.h" -#include "shared.hh" +#include "nix-daemon.hh" #include "local-store.hh" #include "util.hh" #include "serialise.hh" diff --git a/nix/nix-daemon/shared.hh b/nix/nix-daemon/nix-daemon.hh similarity index 81% rename from nix/nix-daemon/shared.hh rename to nix/nix-daemon/nix-daemon.hh index 98ec97410b7..8791c4f21fd 100644 --- a/nix/nix-daemon/shared.hh +++ b/nix/nix-daemon/nix-daemon.hh @@ -20,9 +20,14 @@ #pragma once +#include + #include #include -extern volatile ::sig_atomic_t blockInt; +/* Variables used by `nix-daemon.cc'. */ +inline volatile ::sig_atomic_t blockInt; +inline char **argvSaved; -extern char **argvSaved; +/* Entry point in `nix-daemon.cc'. */ +void run (const std::vector &);