From bba4e6b061f53cbc77d47408468f9bc0f534281b Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Tue, 18 Feb 2025 11:22:00 +0100 Subject: [PATCH] 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. --- src/libstore/globals.cc | 2 +- src/libstore/globals.hh | 10 +++++++++- src/nix/main.cc | 2 ++ src/nix/meson.build | 3 +++ src/nix/package.nix | 6 +++--- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc index e908fc81f..d7c000dfa 100644 --- a/src/libstore/globals.cc +++ b/src/libstore/globals.cc @@ -242,7 +242,7 @@ Path Settings::getDefaultSSLCertFile() return ""; } -const std::string nixVersion = PACKAGE_VERSION; +std::string nixVersion = PACKAGE_VERSION; NLOHMANN_JSON_SERIALIZE_ENUM(SandboxMode, { {SandboxMode::smEnabled, true}, diff --git a/src/libstore/globals.hh b/src/libstore/globals.hh index d0e6f33d4..f62644ff1 100644 --- a/src/libstore/globals.hh +++ b/src/libstore/globals.hh @@ -1248,7 +1248,15 @@ void loadConfFile(AbstractConfig & config); // Used by the Settings constructor std::vector getUserConfigFiles(); -extern const std::string nixVersion; +/** + * The version of Nix itself. + * + * This is not `const`, so that the Nix CLI can provide a more detailed version + * number including the git revision, without having to "re-compile" the entire + * set of Nix libraries to include that version, even when those libraries are + * not affected by the change. + */ +extern std::string nixVersion; /** * @param loadConfig Whether to load configuration from `nix.conf`, `NIX_CONFIG`, etc. May be disabled for unit tests. diff --git a/src/nix/main.cc b/src/nix/main.cc index 80ef53084..f8d0100ac 100644 --- a/src/nix/main.cc +++ b/src/nix/main.cc @@ -557,6 +557,8 @@ void mainWrapped(int argc, char * * argv) int main(int argc, char * * argv) { + // The CLI has a more detailed version than the libraries; see nixVersion. + nix::nixVersion = NIX_CLI_VERSION; #ifndef _WIN32 // Increase the default stack size for the evaluator and for // libstdc++'s std::regex. diff --git a/src/nix/meson.build b/src/nix/meson.build index 25aa1e668..398750498 100644 --- a/src/nix/meson.build +++ b/src/nix/meson.build @@ -35,6 +35,9 @@ subdir('nix-meson-build-support/windows-version') configdata = configuration_data() +# The CLI has a more detailed version string than the libraries; see `nixVersion` +configdata.set_quoted('NIX_CLI_VERSION', meson.project_version()) + fs = import('fs') bindir = get_option('bindir') diff --git a/src/nix/package.nix b/src/nix/package.nix index 6e59adc38..bb90be1ef 100644 --- a/src/nix/package.nix +++ b/src/nix/package.nix @@ -92,11 +92,11 @@ mkMesonExecutable (finalAttrs: { ]; preConfigure = - # "Inline" .version so it's not a symlink, and includes the suffix. - # Do the meson utils, without modification. + # Update the repo-global .version file. + # Symlink ./.version points there, but by default only workDir is writable. '' chmod u+w ./.version - echo ${version} > ../../../.version + echo ${version} > ./.version ''; mesonFlags = [