summaryrefslogtreecommitdiff
path: root/nix
diff options
context:
space:
mode:
authorCongcong Kuo <congcong.kuo@gmail.com>2025-10-20 11:39:00 +0800
committerLudovic Courtès <ludo@gnu.org>2025-11-12 18:34:06 +0100
commitd1a9fb85a4d46722f06d01bde6f61acae3d9ea7a (patch)
tree30aeae6c569b01d614ecc38a3e4eb86321a53ecd /nix
parent6fe5e7f70714735a7a365c73965fc0bfdb3f9f31 (diff)
daemon: Use inline functions and variables instead of extern
Avoid separate declarations and definitions for so-called 'global' objects. * nix/libstore/derivations.{cc, hh} (drvHashes): Use inline instead of separate declaration and definition. * nix/libstore/globals.{cc, hh} (settings, nixVersion): Same. * nix/libstore/local-store.hh (drvsLogDir, deduplicationMinSize): Same. * nix/libstore/optimise-store.cc (deduplicationMinSize): Same. * nix/libstore/store-api.{cc, hh} (store): Same. * nix/libutil/archive.{cc, hh} (defaultPathFilter): Same. * nix/libutil/hash.{cc, hh} (base32Chars): Same and modify header files. * nix/libutil/util.{cc, hh} (logType, verbosity, _writeToStderr, _isInterrupted): Same. * nix/local.mk: Modified according to the rename of shared.hh. * nix/nix-daemon/guix-daemon.cc (blockInt, argvSaved, run): Same and modify header files. * nix/nix-daemon/nix-daemon.cc: Modify header files. * nix/nix-daemon/shared.hh: Renamed to nix-daemon.hh Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'nix')
-rw-r--r--nix/libstore/build.cc3
-rw-r--r--nix/libstore/derivations.cc3
-rw-r--r--nix/libstore/derivations.hh2
-rw-r--r--nix/libstore/globals.cc6
-rw-r--r--nix/libstore/globals.hh4
-rw-r--r--nix/libstore/local-store.hh6
-rw-r--r--nix/libstore/optimise-store.cc3
-rw-r--r--nix/libstore/store-api.cc13
-rw-r--r--nix/libstore/store-api.hh2
-rw-r--r--nix/libutil/archive.cc2
-rw-r--r--nix/libutil/archive.hh2
-rw-r--r--nix/libutil/hash.cc4
-rw-r--r--nix/libutil/hash.hh7
-rw-r--r--nix/libutil/util.cc7
-rw-r--r--nix/libutil/util.hh8
-rw-r--r--nix/local.mk2
-rw-r--r--nix/nix-daemon/guix-daemon.cc17
-rw-r--r--nix/nix-daemon/nix-daemon.cc2
-rw-r--r--nix/nix-daemon/nix-daemon.hh (renamed from nix/nix-daemon/shared.hh)9
19 files changed, 30 insertions, 72 deletions
diff --git a/nix/libstore/build.cc b/nix/libstore/build.cc
index 9010ca4e20..935f7aacf8 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 f05296702b..b6203b1e38 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 8d5e4d05d4..0fbab3a7a4 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<Path, Hash> 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 8551fea56c..885ba4eafc 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 7cfa06e76c..c2824789ed 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 20d3c3c893..4d529b37a4 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 d69c43e997..54aa166c34 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 1067e44a8e..26d44f78b1 100644
--- a/nix/libstore/store-api.cc
+++ b/nix/libstore/store-api.cc
@@ -253,16 +253,3 @@ template<class T> T readStorePaths(Source & from)
template PathSet readStorePaths(Source & from);
}
-
-
-#include "local-store.hh"
-#include "serialise.hh"
-
-
-namespace nix {
-
-
-std::shared_ptr<StoreAPI> store;
-
-
-}
diff --git a/nix/libstore/store-api.hh b/nix/libstore/store-api.hh
index 32a8f2c795..affa98b179 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<StoreAPI> store;
+inline std::shared_ptr<StoreAPI> 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 fa9f4398e3..938fe8d449 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 9b83a5f288..03716ab469 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 57b369d4a9..ac9eb14514 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 1a6b35f074..cedb5077c1 100644
--- a/nix/libutil/hash.hh
+++ b/nix/libutil/hash.hh
@@ -2,14 +2,15 @@
#include <gcrypt.h>
+#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<Hash, unsigned long long> HashResult;
HashResult hashPath(HashType ht, const Path & path,
PathFilter & filter = defaultPathFilter);
diff --git a/nix/libutil/util.cc b/nix/libutil/util.cc
index 22022db51a..ed1a371dfe 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 436c378cb6..42cb60ea0d 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 819131b5d4..2c93670843 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 af09839932..341e39c290 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 <http://www.gnu.org/licenses/>. */
-#include <config.h>
+#include "config.h"
-#include <types.hh>
-#include "shared.hh"
-#include <globals.hh>
-#include <util.hh>
+#include "types.hh"
+#include "nix-daemon.hh"
+#include "globals.hh"
+#include "util.hh"
#include <gcrypt.h>
@@ -36,20 +36,13 @@
#include <netdb.h>
#include <strings.h>
#include <exception>
-#include <iostream>
#include <format>
#include <libintl.h>
#include <locale.h>
-/* 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<int> &);
/* Command-line options. */
diff --git a/nix/nix-daemon/nix-daemon.cc b/nix/nix-daemon/nix-daemon.cc
index 3890adb2c7..b3cdb699ac 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
index 98ec97410b..8791c4f21f 100644
--- a/nix/nix-daemon/shared.hh
+++ b/nix/nix-daemon/nix-daemon.hh
@@ -20,9 +20,14 @@
#pragma once
+#include <vector>
+
#include <stdlib.h>
#include <signal.h>
-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<int> &);