Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore detailed Nix CLI version #12498

Merged
merged 3 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libstore/globals.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
10 changes: 9 additions & 1 deletion src/libstore/globals.hh
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,15 @@ void loadConfFile(AbstractConfig & config);
// Used by the Settings constructor
std::vector<Path> 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.
Expand Down
2 changes: 2 additions & 0 deletions src/nix/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions src/nix/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
6 changes: 3 additions & 3 deletions src/nix/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bad target.

I'll apply this change to all components.

echo ${version} > ./.version
'';

mesonFlags = [
Expand Down
Loading