1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2024-10-18 00:16:11 -04:00

Make getDstStore() a virtual method in StoreCommand

This commit is contained in:
Eelco Dolstra 2024-10-08 15:36:21 +02:00
parent 76f75e7691
commit 43ad8c5eb2
6 changed files with 26 additions and 21 deletions

View file

@ -246,21 +246,17 @@ MixProfile::MixProfile()
});
}
void MixProfile::updateProfile(
const StorePath & storePath,
ref<Store> store_)
void MixProfile::updateProfile(const StorePath & storePath)
{
if (!profile) return;
auto store = store_.dynamic_pointer_cast<LocalFSStore>();
auto store = getDstStore().dynamic_pointer_cast<LocalFSStore>();
if (!store) throw Error("'--profile' is not supported for this Nix store");
auto profile2 = absPath(*profile);
switchLink(profile2,
createGeneration(*store, profile2, storePath));
}
void MixProfile::updateProfile(
const BuiltPaths & buildables,
ref<Store> store)
void MixProfile::updateProfile(const BuiltPaths & buildables)
{
if (!profile) return;
@ -282,7 +278,7 @@ void MixProfile::updateProfile(
if (result.size() != 1)
throw UsageError("'--profile' requires that the arguments produce a single store path, but there are %d", result.size());
updateProfile(result[0], store);
updateProfile(result[0]);
}
MixDefaultProfile::MixDefaultProfile()

View file

@ -45,7 +45,20 @@ struct StoreCommand : virtual Command
{
StoreCommand();
void run() override;
/**
* Return the default Nix store.
*/
ref<Store> getStore();
/**
* Return the destination Nix store.
*/
virtual ref<Store> getDstStore()
{
return getStore();
}
virtual ref<Store> createStore();
/**
* Main entry point, with a `Store` provided
@ -68,7 +81,7 @@ struct CopyCommand : virtual StoreCommand
ref<Store> createStore() override;
ref<Store> getDstStore();
ref<Store> getDstStore() override;
};
/**
@ -301,15 +314,11 @@ struct MixProfile : virtual StoreCommand
MixProfile();
/* If 'profile' is set, make it point at 'storePath'. */
void updateProfile(
const StorePath & storePath,
ref<Store> store);
void updateProfile(const StorePath & storePath);
/* If 'profile' is set, make it point at the store path produced
by 'buildables'. */
void updateProfile(
const BuiltPaths & buildables,
ref<Store> store);
void updateProfile(const BuiltPaths & buildables);
};
struct MixDefaultProfile : MixProfile

View file

@ -161,7 +161,7 @@ struct CmdBuild : InstallablesCommand, MixDryRun, MixJSON, MixProfile
BuiltPaths buildables2;
for (auto & b : buildables)
buildables2.push_back(b.path);
updateProfile(buildables2, store);
updateProfile(buildables2);
}
};

View file

@ -57,7 +57,7 @@ struct CmdCopy : virtual CopyCommand, virtual BuiltPathsCommand, MixProfile
copyPaths(
*srcStore, *dstStore, stuffToCopy, NoRepair, checkSigs, substitute);
updateProfile(rootPaths, dstStore);
updateProfile(rootPaths);
}
};

View file

@ -502,7 +502,7 @@ struct Common : InstallableCommand, MixProfile
auto strPath = store->printStorePath(shellOutPath);
updateProfile(shellOutPath, store);
updateProfile(shellOutPath);
debug("reading environment file '%s'", strPath);

View file

@ -424,7 +424,7 @@ struct CmdProfileInstall : InstallablesCommand, MixDefaultProfile
}
try {
updateProfile(manifest.build(store), store);
updateProfile(manifest.build(store));
} catch (BuildEnvFileConflictError & conflictError) {
// FIXME use C++20 std::ranges once macOS has it
// See https://github.com/NixOS/nix/compare/3efa476c5439f8f6c1968a6ba20a31d1239c2f04..1fe5d172ece51a619e879c4b86f603d9495cc102
@ -669,7 +669,7 @@ struct CmdProfileRemove : virtual EvalCommand, MixDefaultProfile, MixProfileElem
removedCount,
newManifest.elements.size());
updateProfile(newManifest.build(store), store);
updateProfile(newManifest.build(store));
}
};
@ -779,7 +779,7 @@ struct CmdProfileUpgrade : virtual SourceExprCommand, MixDefaultProfile, MixProf
builtPaths.find(&*installable)->second.first);
}
updateProfile(manifest.build(store), store);
updateProfile(manifest.build(store));
}
};