Skip to content

Remove dependent realisations#14247

Merged
Ericson2314 merged 1 commit intoNixOS:masterfrom
obsidiansystems:no-dependent-realisations
Dec 17, 2025
Merged

Remove dependent realisations#14247
Ericson2314 merged 1 commit intoNixOS:masterfrom
obsidiansystems:no-dependent-realisations

Conversation

@Ericson2314
Copy link
Copy Markdown
Member

@Ericson2314 Ericson2314 commented Oct 14, 2025

Motivation

This progress on #11896. It introduces some issues temporarily which will be fixed when #11928 is fixed.

Context

The SQL tables are left in place because there is no point inducing a migration now, when we will be immediately landing more changes after this that also require schema changes. They will simply be ignored by in this commit, and so all data will be preserved.

Depends on #14465
Depends on #14425
Depends on #13942
Depends on #14793


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@Ericson2314 Ericson2314 requested a review from edolstra as a code owner October 14, 2025 18:19
@github-actions github-actions bot added documentation new-cli Relating to the "nix" command with-tests Issues related to testing. PRs with tests have some priority store Issues and pull requests concerning the Nix store labels Oct 14, 2025
@Ericson2314 Ericson2314 force-pushed the no-dependent-realisations branch 4 times, most recently from c03e01e to d795f87 Compare October 20, 2025 20:50
@Ericson2314 Ericson2314 force-pushed the no-dependent-realisations branch from d795f87 to 15f3abb Compare October 23, 2025 16:42
Ericson2314 added a commit to obsidiansystems/nix that referenced this pull request Nov 3, 2025
This will allow us to more accurately test dropping support for
dependent realisations, by separating the tests that should not change
from the tests that should.

I do that change in PR NixOS#14247, but even if for some reasons we don't end
up doing this soon, I think it is still good to separate the test data
this way so we have the option of doing that at some point.
@Ericson2314 Ericson2314 force-pushed the no-dependent-realisations branch 3 times, most recently from 78329ec to 2f799fe Compare November 6, 2025 18:29
@dpulls
Copy link
Copy Markdown

dpulls bot commented Nov 6, 2025

🎉 All dependencies have been resolved !

@Ericson2314 Ericson2314 force-pushed the no-dependent-realisations branch 2 times, most recently from fad08df to 5fed736 Compare November 6, 2025 22:14
@Ericson2314 Ericson2314 force-pushed the no-dependent-realisations branch 4 times, most recently from aed2570 to 8c3e710 Compare November 21, 2025 05:21
@dpulls
Copy link
Copy Markdown

dpulls bot commented Nov 24, 2025

🎉 All dependencies have been resolved !

Copy link
Copy Markdown
Member Author

@Ericson2314 Ericson2314 Nov 26, 2025

Choose a reason for hiding this comment

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

I need to figure out how the migration for this works. CC @edolstra, do you know?

@Ericson2314 Ericson2314 force-pushed the no-dependent-realisations branch from fecd798 to 0c33c8d Compare December 4, 2025 15:22
@Ericson2314 Ericson2314 force-pushed the no-dependent-realisations branch 6 times, most recently from 6900a7f to 3986922 Compare December 13, 2025 17:12
@Ericson2314 Ericson2314 force-pushed the no-dependent-realisations branch from 3986922 to 809bafb Compare December 15, 2025 07:12
Comment on lines +602 to +608
throw Error(
"Migrating the database schema for the '%s' experimental feature is not yet supported.\n\n"
"Either downgrade Nix to a version that supports the old schema, "
"or disable the '%s' experimental feature.\n\n"
"Note: Disabling the experimental feature will safely leave all existing data intact.",
showExperimentalFeature(Xp::CaDerivations),
showExperimentalFeature(Xp::CaDerivations));
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is the temporary so I can make progress on this stuff. When I am done and we have something that looks stable, we can then think about how to write this migration.

Copy link
Copy Markdown
Member

@Mic92 Mic92 Dec 16, 2025

Choose a reason for hiding this comment

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

That's not a great migration. I changed it to this instead:

From 9366ff4c02275d2d1bf35cd27d94ba5952071485 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= <joerg@thalheim.io>
Date: Tue, 16 Dec 2025 19:53:12 +0100
Subject: [PATCH] local-store: better migration for RealisationsRefs removal
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The previous commit removed usage of the RealisationsRefs table but
threw an error for existing databases with CA derivations enabled,
blocking deployment entirely.

Instead of erroring, keep the old table around for backwards
compatibility with older Nix versions that may still share the
database. They will continue to populate it while new Nix simply
ignores it. This allows mixed-version deployments during upgrades.

Signed-off-by: Jörg Thalheim <joerg@thalheim.io>
---
 src/libstore/local-store.cc | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index 080b454b6..df6d5cc7d 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -598,14 +598,15 @@ void LocalStore::upgradeDBSchema(State & state)
                     "20251013-remove-realisations-refs",
                 });
         } else if (!schemaMigrations.contains("20251013-remove-realisations-refs")) {
-            /* CA drvs previously enabled with old schema. */
-            throw Error(
-                "Migrating the database schema for the '%s' experimental feature is not yet supported.\n\n"
-                "Either downgrade Nix to a version that supports the old schema, "
-                "or disable the '%s' experimental feature.\n\n"
-                "Note: Disabling the experimental feature will safely leave all existing data intact.",
-                showExperimentalFeature(Xp::CaDerivations),
-                showExperimentalFeature(Xp::CaDerivations));
+            /* CA drvs previously enabled with old schema. The new code no
+               longer uses the RealisationsRefs table, but we keep it around
+               for backwards compatibility with older Nix versions that may
+               still share this database. They will continue to populate it,
+               but we simply ignore it. */
+            debug("executing Nix database schema migration '%s'...", "20251013-remove-realisations-refs");
+
+            SQLiteTxn txn(state.db);
+            commitAndMarkMigrations(txn, {"20251013-remove-realisations-refs"});
         }
     }
 }
-- 
2.50.1

Otherwise I wouldn't be able to upgrade at all. But I am wondering, why can we not keep the migration linear and just ignore the fact that we have a few empty tables in the schema? It would help when people upgrade/downgrade Nix versions.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I was worried about the foreign keys, but I guess the on-delete cascade will help with that?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

As @Mic92 and I discussed, there is no more schema change at all.

@dpulls
Copy link
Copy Markdown

dpulls bot commented Dec 16, 2025

🎉 All dependencies have been resolved !

@Ericson2314 Ericson2314 force-pushed the no-dependent-realisations branch from 809bafb to 7e34eea Compare December 17, 2025 00:09
Comment on lines +69 to +77
/**
* Execute a SQL statement. The string must be null-terminated.
*/
void exec(const char * stmt);

void exec(const std::string & stmt)
{
exec(stmt.c_str());
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems like some leftover thing?

This progress on NixOS#11896. It introduces some issues temporarily which
will be fixed when NixOS#11928 is fixed.

The SQL tables are left in place because there is no point inducing a
migration now, when we will be immediately landing more changes after
this that also require schema changes. They will simply be ignored by in
this commit, and so all data will be preserved.
Comment on lines +918 to +923
std::vector<const Realisation *> realisations;
for (auto & path : paths) {
storePaths.insert(path.path());
if (auto * realisation = std::get_if<Realisation>(&path.raw)) {
experimentalFeatureSettings.require(Xp::CaDerivations);
toplevelRealisations.insert(*realisation);
realisations.push_back(realisation);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this some kind of optimisation? We can split this out right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Discussed 1-1, is because I get rid of the closure method because we didn't really need it any more. This is just some inlined remnants of it.

@Ericson2314 Ericson2314 force-pushed the no-dependent-realisations branch from 7e34eea to 4a5d960 Compare December 17, 2025 01:13
@Ericson2314 Ericson2314 added this pull request to the merge queue Dec 17, 2025
Merged via the queue into NixOS:master with commit f536b25 Dec 17, 2025
16 checks passed
@Ericson2314 Ericson2314 deleted the no-dependent-realisations branch December 17, 2025 02:55
brittonr pushed a commit to brittonr/nix that referenced this pull request Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation new-cli Relating to the "nix" command store Issues and pull requests concerning the Nix store with-tests Issues related to testing. PRs with tests have some priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants