Skip to content

Commit

Permalink
Merge pull request #12506 from NixOS/mergify/bp/2.26-maintenance/pr-1…
Browse files Browse the repository at this point in the history
…2498

Restore detailed Nix CLI version (backport #12498)
  • Loading branch information
mergify[bot] authored Feb 19, 2025
2 parents d6a66b3 + fd06258 commit 8a2bb81
Show file tree
Hide file tree
Showing 28 changed files with 35 additions and 181 deletions.
15 changes: 15 additions & 0 deletions packaging/dependencies.nix
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ let
mkPackageBuilder =
exts: userFn: stdenv.mkDerivation (lib.extends (lib.composeManyExtensions exts) userFn);

setVersionLayer = finalAttrs: prevAttrs: {
preConfigure =
prevAttrs.prevAttrs or ""
+
# Update the repo-global .version file.
# Symlink ./.version points there, but by default only workDir is writable.
''
chmod u+w ./.version
echo ${finalAttrs.version} > ./.version
'';
};

localSourceLayer =
finalAttrs: prevAttrs:
let
Expand Down Expand Up @@ -180,12 +192,14 @@ scope:
mkMesonDerivation = mkPackageBuilder [
miscGoodPractice
localSourceLayer
setVersionLayer
mesonLayer
];
mkMesonExecutable = mkPackageBuilder [
miscGoodPractice
bsdNoLinkAsNeeded
localSourceLayer
setVersionLayer
mesonLayer
mesonBuildLayer
];
Expand All @@ -194,6 +208,7 @@ scope:
bsdNoLinkAsNeeded
localSourceLayer
mesonLayer
setVersionLayer
mesonBuildLayer
mesonLibraryLayer
];
Expand Down
8 changes: 0 additions & 8 deletions src/libcmd/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,6 @@ mkMesonLibrary (finalAttrs: {
nlohmann_json
];

preConfigure =
# "Inline" .version so it's not a symlink, and includes the suffix.
# Do the meson utils, without modification.
''
chmod u+w ./.version
echo ${version} > ../../.version
'';

mesonFlags = [
(lib.mesonEnable "markdown" enableMarkdown)
(lib.mesonOption "readline-flavor" readlineFlavor)
Expand Down
8 changes: 0 additions & 8 deletions src/libexpr-c/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ mkMesonLibrary (finalAttrs: {
nix-expr
];

preConfigure =
# "Inline" .version so it's not a symlink, and includes the suffix.
# Do the meson utils, without modification.
''
chmod u+w ./.version
echo ${version} > ../../.version
'';

mesonFlags = [
];

Expand Down
8 changes: 0 additions & 8 deletions src/libexpr-test-support/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,6 @@ mkMesonLibrary (finalAttrs: {
rapidcheck
];

preConfigure =
# "Inline" .version so it's not a symlink, and includes the suffix.
# Do the meson utils, without modification.
''
chmod u+w ./.version
echo ${version} > ../../.version
'';

mesonFlags = [
];

Expand Down
8 changes: 0 additions & 8 deletions src/libexpr-tests/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@ mkMesonExecutable (finalAttrs: {
gtest
];

preConfigure =
# "Inline" .version so it's not a symlink, and includes the suffix.
# Do the meson utils, without modification.
''
chmod u+w ./.version
echo ${version} > ../../.version
'';

mesonFlags = [
];

Expand Down
8 changes: 0 additions & 8 deletions src/libexpr/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,6 @@ mkMesonLibrary (finalAttrs: {
nlohmann_json
] ++ lib.optional enableGC boehmgc;

preConfigure =
# "Inline" .version so it's not a symlink, and includes the suffix.
# Do the meson utils, without modification.
''
chmod u+w ./.version
echo ${version} > ../../.version
'';

mesonFlags = [
(lib.mesonEnable "gc" enableGC)
];
Expand Down
8 changes: 0 additions & 8 deletions src/libfetchers-tests/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@ mkMesonExecutable (finalAttrs: {
gtest
];

preConfigure =
# "Inline" .version so it's not a symlink, and includes the suffix.
# Do the meson utils, without modification.
''
chmod u+w ./.version
echo ${version} > ../../.version
'';

mesonFlags = [
];

Expand Down
8 changes: 0 additions & 8 deletions src/libfetchers/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@ mkMesonLibrary (finalAttrs: {
nlohmann_json
];

preConfigure =
# "Inline" .version so it's not a symlink, and includes the suffix.
# Do the meson utils, without modification.
''
chmod u+w ./.version
echo ${version} > ../../.version
'';

meta = {
platforms = lib.platforms.unix ++ lib.platforms.windows;
};
Expand Down
8 changes: 0 additions & 8 deletions src/libflake-c/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ mkMesonLibrary (finalAttrs: {
nix-flake
];

preConfigure =
# "Inline" .version so it's not a symlink, and includes the suffix.
# Do the meson utils, without modification.
''
chmod u+w ./.version
echo ${version} > ../../.version
'';

mesonFlags = [
];

Expand Down
8 changes: 0 additions & 8 deletions src/libflake-tests/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@ mkMesonExecutable (finalAttrs: {
gtest
];

preConfigure =
# "Inline" .version so it's not a symlink, and includes the suffix.
# Do the meson utils, without modification.
''
chmod u+w ./.version
echo ${version} > ../../.version
'';

mesonFlags = [
];

Expand Down
8 changes: 0 additions & 8 deletions src/libflake/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,6 @@ mkMesonLibrary (finalAttrs: {
nlohmann_json
];

preConfigure =
# "Inline" .version so it's not a symlink, and includes the suffix.
# Do the meson utils, without modification.
''
chmod u+w ./.version
echo ${version} > ../../.version
'';

meta = {
platforms = lib.platforms.unix ++ lib.platforms.windows;
};
Expand Down
8 changes: 0 additions & 8 deletions src/libmain-c/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,6 @@ mkMesonLibrary (finalAttrs: {
nix-main
];

preConfigure =
# "Inline" .version so it's not a symlink, and includes the suffix.
# Do the meson utils, without modification.
''
chmod u+w ./.version
echo ${version} > ../../.version
'';

mesonFlags = [
];

Expand Down
8 changes: 0 additions & 8 deletions src/libmain/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ mkMesonLibrary (finalAttrs: {
openssl
];

preConfigure =
# "Inline" .version so it's not a symlink, and includes the suffix.
# Do the meson utils, without modification.
''
chmod u+w ./.version
echo ${version} > ../../.version
'';

meta = {
platforms = lib.platforms.unix ++ lib.platforms.windows;
};
Expand Down
8 changes: 0 additions & 8 deletions src/libstore-c/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ mkMesonLibrary (finalAttrs: {
nix-store
];

preConfigure =
# "Inline" .version so it's not a symlink, and includes the suffix.
# Do the meson utils, without modification.
''
chmod u+w ./.version
echo ${version} > ../../.version
'';

mesonFlags = [
];

Expand Down
8 changes: 0 additions & 8 deletions src/libstore-test-support/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,6 @@ mkMesonLibrary (finalAttrs: {
rapidcheck
];

preConfigure =
# "Inline" .version so it's not a symlink, and includes the suffix.
# Do the meson utils, without modification.
''
chmod u+w ./.version
echo ${version} > ../../.version
'';

mesonFlags = [
];

Expand Down
8 changes: 0 additions & 8 deletions src/libstore-tests/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ mkMesonExecutable (finalAttrs: {
nix-store-test-support
];

preConfigure =
# "Inline" .version so it's not a symlink, and includes the suffix.
# Do the meson utils, without modification.
''
chmod u+w ./.version
echo ${version} > ../../.version
'';

mesonFlags = [
];

Expand Down
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
8 changes: 0 additions & 8 deletions src/libstore/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,6 @@ mkMesonLibrary (finalAttrs: {
nlohmann_json
];

preConfigure =
# "Inline" .version so it's not a symlink, and includes the suffix.
# Do the meson utils, without modification.
''
chmod u+w ./.version
echo ${version} > ../../.version
'';

mesonFlags =
[
(lib.mesonEnable "seccomp-sandboxing" stdenv.hostPlatform.isLinux)
Expand Down
8 changes: 0 additions & 8 deletions src/libutil-c/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@ mkMesonLibrary (finalAttrs: {
nix-util
];

preConfigure =
# "Inline" .version so it's not a symlink, and includes the suffix.
# Do the meson utils, without modification.
''
chmod u+w ./.version
echo ${version} > ../../.version
'';

mesonFlags = [
];

Expand Down
8 changes: 0 additions & 8 deletions src/libutil-test-support/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ mkMesonLibrary (finalAttrs: {
rapidcheck
];

preConfigure =
# "Inline" .version so it's not a symlink, and includes the suffix.
# Do the meson utils, without modification.
''
chmod u+w ./.version
echo ${version} > ../../.version
'';

mesonFlags = [
];

Expand Down
8 changes: 0 additions & 8 deletions src/libutil-tests/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@ mkMesonExecutable (finalAttrs: {
gtest
];

preConfigure =
# "Inline" .version so it's not a symlink, and includes the suffix.
# Do the meson utils, without modification.
''
chmod u+w ./.version
echo ${version} > ../../.version
'';

mesonFlags = [
];

Expand Down
11 changes: 0 additions & 11 deletions src/libutil/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,6 @@ mkMesonLibrary (finalAttrs: {
nlohmann_json
];

preConfigure =
# "Inline" .version so it's not a symlink, and includes the suffix.
# Do the meson utils, without modification.
#
# TODO: change release process to add `pre` in `.version`, remove it
# before tagging, and restore after.
''
chmod u+w ./.version
echo ${version} > ../../.version
'';

mesonFlags = [
(lib.mesonEnable "cpuid" stdenv.hostPlatform.isx86_64)
];
Expand Down
3 changes: 3 additions & 0 deletions src/nix/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,9 @@ 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;

// Increase the default stack size for the evaluator and for
// libstdc++'s std::regex.
nix::setStackSize(64 * 1024 * 1024);
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
Loading

0 comments on commit 8a2bb81

Please sign in to comment.