@@ -337,13 +337,16 @@ LocalStore::LocalStore(ref<const Config> config)
337337 /* Prepare SQL statements. */
338338 state->stmts ->RegisterValidPath .create (
339339 state->db ,
340- " insert into ValidPaths (path, hash, registrationTime, deriver, narSize, ultimate, sigs, ca, provenance) values (?, ?, ?, ?, ?, ?, ?, ?, ?);" );
340+ fmt (" insert into ValidPaths (path, hash, registrationTime, deriver, narSize, ultimate, sigs, ca%s) values (?, ?, ?, ?, ?, ?, ?, ?%s);" ,
341+ experimentalFeatureSettings.isEnabled (Xp::Provenance) ? " , provenance" : " " ,
342+ experimentalFeatureSettings.isEnabled (Xp::Provenance) ? " , ?" : " " ));
341343 state->stmts ->UpdatePathInfo .create (
342344 state->db , " update ValidPaths set narSize = ?, hash = ?, ultimate = ?, sigs = ?, ca = ? where path = ?;" );
343345 state->stmts ->AddReference .create (state->db , " insert or replace into Refs (referrer, reference) values (?, ?);" );
344346 state->stmts ->QueryPathInfo .create (
345347 state->db ,
346- " select id, hash, registrationTime, deriver, narSize, ultimate, sigs, ca, provenance from ValidPaths where path = ?;" );
348+ fmt (" select id, hash, registrationTime, deriver, narSize, ultimate, sigs, ca%s from ValidPaths where path = ?;" ,
349+ experimentalFeatureSettings.isEnabled (Xp::Provenance) ? " , provenance" : " " ));
347350 state->stmts ->QueryReferences .create (
348351 state->db , " select path from Refs join ValidPaths on reference = id where referrer = ?;" );
349352 state->stmts ->QueryReferrers .create (
@@ -599,7 +602,8 @@ void LocalStore::upgradeDBSchema(State & state)
599602#include " ca-specific-schema.sql.gen.hh"
600603 );
601604
602- doUpgrade (" 20241024-provenance" , " alter table ValidPaths add column provenance text" );
605+ if (experimentalFeatureSettings.isEnabled (Xp::Provenance))
606+ doUpgrade (" 20241024-provenance" , " alter table ValidPaths add column provenance text" );
603607}
604608
605609/* To improve purity, users may want to make the Nix store a read-only
@@ -695,14 +699,14 @@ uint64_t LocalStore::addValidPath(State & state, const ValidPathInfo & info, boo
695699 " cannot add path '%s' to the Nix store because it claims to be content-addressed but isn't" ,
696700 printStorePath (info.path ));
697701
698- state.stmts ->RegisterValidPath
699- . use ()( printStorePath ( info.path ))(info. narHash .to_string (HashFormat::Base16, true ))(
700- info.registrationTime == 0 ? time ( 0 ) : info. registrationTime )(
701- info.deriver ? printStorePath (* info.deriver ) : " " ,
702- ( bool ) info.deriver )(info. narSize , info.narSize != 0 )( info.ultimate ? 1 : 0 , info.ultimate )(
703- concatStringsSep ( " " , info. sigs ), !info. sigs . empty ())( renderContentAddress (info. ca ), ( bool ) info. ca )(
704- info.provenance ? info.provenance ->to_json_str () : " " , (bool ) info.provenance )
705- .exec ();
702+ auto query = state.stmts ->RegisterValidPath . use ()( printStorePath (info. path ))(
703+ info.narHash .to_string (HashFormat::Base16, true ))(info. registrationTime == 0 ? time ( 0 ) : info. registrationTime )(
704+ info.deriver ? printStorePath (*info. deriver ) : " " ,
705+ ( bool ) info.deriver )(info. narSize , info. narSize != 0 )( info.ultimate ? 1 : 0 , info. ultimate )(
706+ concatStringsSep ( " " , info.sigs ), ! info.sigs . empty ())( renderContentAddress ( info.ca ), ( bool ) info.ca );
707+ if (experimentalFeatureSettings. isEnabled (Xp::Provenance))
708+ query ( info.provenance ? info.provenance ->to_json_str () : " " , (bool ) info.provenance );
709+ query .exec ();
706710 uint64_t id = state.db .getLastInsertedRowId ();
707711
708712 /* If this is a derivation, then store the derivation outputs in
@@ -792,9 +796,11 @@ std::shared_ptr<const ValidPathInfo> LocalStore::queryPathInfoInternal(State & s
792796 while (useQueryReferences.next ())
793797 info->references .insert (parseStorePath (useQueryReferences.getStr (0 )));
794798
795- auto prov = (const char *) sqlite3_column_text (state.stmts ->QueryPathInfo , 8 );
796- if (prov)
797- info->provenance = Provenance::from_json_str (prov);
799+ if (experimentalFeatureSettings.isEnabled (Xp::Provenance)) {
800+ auto prov = (const char *) sqlite3_column_text (state.stmts ->QueryPathInfo , 8 );
801+ if (prov)
802+ info->provenance = Provenance::from_json_str (prov);
803+ }
798804
799805 return info;
800806}
0 commit comments