Skip to content

Commit bba4e6b

Browse files
committed
Restore detailed Nix CLI version
... as intended. Requirements: - don't build fresh libraries for each git commit - have git commit in the CLI Bug: - echo ${version} went into the wrong file => use the fact that it's a symlink, not just for reading but also for writing.
1 parent 9427c02 commit bba4e6b

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

src/libstore/globals.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ Path Settings::getDefaultSSLCertFile()
242242
return "";
243243
}
244244

245-
const std::string nixVersion = PACKAGE_VERSION;
245+
std::string nixVersion = PACKAGE_VERSION;
246246

247247
NLOHMANN_JSON_SERIALIZE_ENUM(SandboxMode, {
248248
{SandboxMode::smEnabled, true},

src/libstore/globals.hh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,15 @@ void loadConfFile(AbstractConfig & config);
12481248
// Used by the Settings constructor
12491249
std::vector<Path> getUserConfigFiles();
12501250

1251-
extern const std::string nixVersion;
1251+
/**
1252+
* The version of Nix itself.
1253+
*
1254+
* This is not `const`, so that the Nix CLI can provide a more detailed version
1255+
* number including the git revision, without having to "re-compile" the entire
1256+
* set of Nix libraries to include that version, even when those libraries are
1257+
* not affected by the change.
1258+
*/
1259+
extern std::string nixVersion;
12521260

12531261
/**
12541262
* @param loadConfig Whether to load configuration from `nix.conf`, `NIX_CONFIG`, etc. May be disabled for unit tests.

src/nix/main.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,8 @@ void mainWrapped(int argc, char * * argv)
557557

558558
int main(int argc, char * * argv)
559559
{
560+
// The CLI has a more detailed version than the libraries; see nixVersion.
561+
nix::nixVersion = NIX_CLI_VERSION;
560562
#ifndef _WIN32
561563
// Increase the default stack size for the evaluator and for
562564
// libstdc++'s std::regex.

src/nix/meson.build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ subdir('nix-meson-build-support/windows-version')
3535

3636
configdata = configuration_data()
3737

38+
# The CLI has a more detailed version string than the libraries; see `nixVersion`
39+
configdata.set_quoted('NIX_CLI_VERSION', meson.project_version())
40+
3841
fs = import('fs')
3942

4043
bindir = get_option('bindir')

src/nix/package.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ mkMesonExecutable (finalAttrs: {
9292
];
9393

9494
preConfigure =
95-
# "Inline" .version so it's not a symlink, and includes the suffix.
96-
# Do the meson utils, without modification.
95+
# Update the repo-global .version file.
96+
# Symlink ./.version points there, but by default only workDir is writable.
9797
''
9898
chmod u+w ./.version
99-
echo ${version} > ../../../.version
99+
echo ${version} > ./.version
100100
'';
101101

102102
mesonFlags = [

0 commit comments

Comments
 (0)